Documentation
¶
Overview ¶
Package fairy contains several general tools for easier and simpler development.
Index ¶
- Variables
- func HandlerFuncWithLog(logger Logger, next http.HandlerFunc) http.HandlerFunc
- func HandlerWithLog(logger Logger, next http.Handler) http.Handler
- func MiddlewareWithLog(logger Logger) func(http.Handler) http.Handler
- type CacheType
- type Cacher
- type Channel
- type ErrStacker
- type LogLevel
- type LogType
- type Logger
- type PubSub
- type PubsubType
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidCacheType = errors.New("invalid cache type")
ErrInvalidCacheType is error for invalid cache type.
var ErrInvalidLogType = errors.New("invalid log type")
ErrInvalidLogType is error for invalid log type.
var ErrInvalidPubsubType = errors.New("invalid pubsub type")
ErrInvalidPubsubType is error for invalid pubsub type.
Functions ¶
func HandlerFuncWithLog ¶
func HandlerFuncWithLog(logger Logger, next http.HandlerFunc) http.HandlerFunc
HandlerFuncWithLog is http handler func with log.
func HandlerWithLog ¶
HandlerWithLog is http handler with log. Also includes error stack tracing feature if you use it.
Types ¶
type Cacher ¶
type Cacher interface {
// Get data from cache. The returned value will be
// assigned to param `data`. Param `data` should
// be a pointer just like when using json.Unmarshal.
Get(key string, data interface{}) error
// Save data to cache. Set and Get should be using
// the same encoding method. For example, json.Marshal
// for Set and json.Unmarshal for Get.
Set(key string, data interface{}) error
// Delete data from cache.
Delete(key string) error
// Close cache connection.
Close() error
}
Cacher is caching interface.
See usage example in example folder.
type Channel ¶
type Channel interface {
// Read and process incoming message. Param `data` should
// be a pointer just like when using json.Unmarshal.
Read(data interface{}) (<-chan interface{}, <-chan error)
// Close subscription.
Close() error
}
Channel is channel interface.
See usage example in example folder.
type ErrStacker ¶ added in v0.2.0
type ErrStacker interface {
// Init the context so it can be used for stack.
Init(ctx context.Context) context.Context
// Wrap the error and put it in the error stack.
Wrap(ctx context.Context, err error, errs ...error) error
// Get the error stack.
Get(ctx context.Context) interface{}
}
ErrStacker is error stack interface.
See usage example in example folder.
func NewErrStacker ¶ added in v0.2.0
func NewErrStacker() ErrStacker
NewErrStacker to create new error stack.
type LogLevel ¶
type LogLevel int8
LogLevel is level of log that will be printed. Will print level that is higher than your chosen one.
type Logger ¶
type Logger interface {
Trace(format string, args ...interface{})
Debug(format string, args ...interface{})
Info(format string, args ...interface{})
Warn(format string, args ...interface{})
Error(format string, args ...interface{})
Fatal(format string, args ...interface{})
Panic(format string, args ...interface{})
// General log with key value.
Log(fields map[string]interface{})
}
Logger is logging interface.
See usage example in example folder.
type PubSub ¶
type PubSub interface {
// Publish message to specific topic/channel.
// Data will be encoded first before publishing.
Publish(topic string, data interface{}) error
// Subscribe to specific topic/channel.
Subscribe(topic string) (interface{}, error)
// Close pubsub client connection.
Close() error
}
PubSub is pubsub interface.
For subscribe function, you have to convert the return type to Channel.
See usage example in example folder.
type PubsubType ¶
type PubsubType int8
PubsubType is type for pubsub.
const ( RedisPubsub PubsubType = iota + 1 RabbitMQ NSQ )
Available types for pubsub.
type Validator ¶
type Validator interface {
// Register custom modifier.
RegisterModifier(name string, fn func(in string) (out string)) error
// Modify struct field value according to modifier tag.
// Param `data` should be a pointer.
Modify(data interface{}) error
// Register custom validator.
RegisterValidator(name string, fn func(value interface{}, param ...string) (ok bool)) error
// Register error message handler.
RegisterValidatorError(name string, fn func(field string, param ...string) (msg error)) error
// Validate struct field value according to validator tag.
// Param `data` should be a pointer.
Validate(data interface{}) error
}
Validator is validating interface.
See usage example in example folder.
func NewValidator ¶
NewValidator to create new validator. Pass true if you want to modify the data automatically before validate.
Directories
¶
| Path | Synopsis |
|---|---|
|
cache
|
|
|
bigcache
Package bigcache is a wrapper of the original "github.com/allegro/bigcache" library.
|
Package bigcache is a wrapper of the original "github.com/allegro/bigcache" library. |
|
memcache
Package memcache is a wrapper of the original "github.com/bradfitz/gomemcache/memcache" library.
|
Package memcache is a wrapper of the original "github.com/bradfitz/gomemcache/memcache" library. |
|
nocache
Package nocache is a mock of caching.
|
Package nocache is a mock of caching. |
|
redis
Package redis is a wrapper of the original "github.com/go-redis/redis" library.
|
Package redis is a wrapper of the original "github.com/go-redis/redis" library. |
|
errors
|
|
|
stack
Package stack is an error wrapper and put it to a stack using passed context.
|
Package stack is an error wrapper and put it to a stack using passed context. |
|
example
|
|
|
cache
command
|
|
|
errors
command
|
|
|
log
command
|
|
|
pubsub/publisher
command
|
|
|
pubsub/subscriber
command
|
|
|
validation
command
|
|
|
log
|
|
|
builtin
Package builtin is a wrapper of the built-in log package.
|
Package builtin is a wrapper of the built-in log package. |
|
logrus
Package logrus is a wrapper of the original "github.com/sirupsen/logrus" library.
|
Package logrus is a wrapper of the original "github.com/sirupsen/logrus" library. |
|
nolog
Package nolog is just a mock of logging which do nothing.
|
Package nolog is just a mock of logging which do nothing. |
|
zerolog
Package zerolog is a wrapper of the original "github.com/rs/zerolog" library.
|
Package zerolog is a wrapper of the original "github.com/rs/zerolog" library. |
|
pubsub
|
|
|
nsq
Package nsq is a wrapper of the original "github.com/nsqio/go-nsq" library.
|
Package nsq is a wrapper of the original "github.com/nsqio/go-nsq" library. |
|
rabbitmq
Package rabbitmq is a wrapper of the original "github.com/streadway/amqp" library.
|
Package rabbitmq is a wrapper of the original "github.com/streadway/amqp" library. |
|
redis
Package redis is a wrapper of the original "github.com/go-redis/redis/v8" library.
|
Package redis is a wrapper of the original "github.com/go-redis/redis/v8" library. |
|
validation
|
|
|
playground
Package playground is a wrapper of the original "github.com/go-playground/validator" and "github.com/go-playground/mold" library.
|
Package playground is a wrapper of the original "github.com/go-playground/validator" and "github.com/go-playground/mold" library. |