common

package
v0.0.0-...-d7d0311 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserExchange     Exchange   = "user_exchange"
	UserCreatedQueue Queue      = "user_created_queue"
	UserCreatedKey   BindingKey = "user.created"
)

Variables

View Source
var (
	ErrRecordNotFound = fmt.Errorf("record not found")
)

Functions

func CacheKeyBlog

func CacheKeyBlog(id int) string

func CacheKeyBlogs

func CacheKeyBlogs(limit, offset int) string

func CacheKeyBlogsByUserId

func CacheKeyBlogsByUserId(id int) string

func CacheKeyLikeCount

func CacheKeyLikeCount(blogID int) string

func CacheKeyLikedUsers

func CacheKeyLikedUsers(blogID int) string

func CacheKeyUserByAccessToken

func CacheKeyUserByAccessToken(token []byte) string

func CacheKeyUserByUsername

func CacheKeyUserByUsername(username string) string

func CloseDB

func CloseDB(db *sql.DB) error

CloseDB closes the database connection

func ForeignKeyError

func ForeignKeyError(err error, name string) bool

func NewDB

func NewDB(host, user, password, name string, maxOpenConns, maxIdleConns int, maxIdleTime time.Duration) (*sql.DB, error)

func SetupUserExchange

func SetupUserExchange(mb *MessageBroker) error

func TestDB

func TestDB(filepath string, t *testing.T) *sql.DB

func TestRabbitMQ

func TestRabbitMQ(t *testing.T) string

Types

type BindingKey

type BindingKey string

type Cache

type Cache struct {
	*cache.Cache
}

func NewCache

func NewCache(expirationTime, cleanupTime time.Duration) *Cache

func (*Cache) Flush

func (c *Cache) Flush()

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, bool)

func (*Cache) Set

func (c *Cache) Set(key string, value interface{}, expiration ...time.Duration)

type Exchange

type Exchange string

type MessageBroker

type MessageBroker struct {
	// contains filtered or unexported fields
}

func NewMessageBroker

func NewMessageBroker(URI string) (*MessageBroker, error)

func (*MessageBroker) Close

func (mb *MessageBroker) Close() error

Close closes the connection and channel of the message broker.

func (*MessageBroker) Consume

func (mb *MessageBroker) Consume(key BindingKey, exchange Exchange, queue Queue) (<-chan amqp.Delivery, error)

func (*MessageBroker) Publish

func (mb *MessageBroker) Publish(ctx context.Context, msg []byte, key BindingKey, exchange Exchange) error

type MessageConsumer

type MessageConsumer interface {
	Consume(key BindingKey, exchange Exchange, queue Queue) (<-chan amqp.Delivery, error)
}

type MessageProducer

type MessageProducer interface {
	Publish(ctx context.Context, msg []byte, key BindingKey, exchange Exchange) error
}

type Queue

type Queue string

type ValidationError

type ValidationError struct {
	Errors map[string]string
}

func (ValidationError) Error

func (e ValidationError) Error() string

type Validator

type Validator struct {
	Errors map[string]string
}

func NewValidator

func NewValidator() *Validator

func (*Validator) AddError

func (v *Validator) AddError(field, message string)

func (*Validator) Check

func (v *Validator) Check(ok bool, field, message string)

func (*Validator) CheckStringLength

func (v *Validator) CheckStringLength(s string, min, max int) bool

func (*Validator) Valid

func (v *Validator) Valid() bool

func (*Validator) ValidationError

func (v *Validator) ValidationError() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL