Documentation ¶
Index ¶
- Constants
- Variables
- func Initialize(provider IProvider)
- type Cache
- func (c *Cache) Build() *cache.Cache
- func (c *Cache) BuildWith(defaultExpiration, cleanupInterval time.Duration) *cache.Cache
- func (c *Cache) Default() *cache.Cache
- func (c *Cache) WithCleanupInterval(cleanupInterval time.Duration) *Cache
- func (c *Cache) WithDefaultExpiration(defaultExpiration time.Duration) *Cache
- type Component
- type Config
- type Container
- func (c *Container) Cache() *Cache
- func (c *Container) Config() *Config
- func (c *Container) Cron() *Cron
- func (c *Container) Curl() *Curl
- func (c *Container) DI() *DI
- func (c *Container) EventDispatcher() *EventDispatcher
- func (c *Container) Get(name string) (Component, bool)
- func (c *Container) GetOrInit(name string) Component
- func (c *Container) Gorm() *Gorm
- func (c *Container) Jwt() *JWT
- func (c *Container) Logger() *Logger
- func (c *Container) Mongo() *Mongo
- func (c *Container) Redis() *Redis
- func (c *Container) Register(components ...Component)
- func (c *Container) Tracer() *Tracer
- func (c *Container) Validator() *Validator
- type Cron
- type Curl
- func (c *Curl) Delete(url string, body io.Reader) (serializer.Serializer, error)
- func (c *Curl) Get(url string) (serializer.Serializer, error)
- func (c *Curl) Post(url string, body io.Reader) (serializer.Serializer, error)
- func (c *Curl) PostFile(url string, files map[string]string, params map[string]string) (serializer.Serializer, error)
- func (c *Curl) Put(url string, body io.Reader) (serializer.Serializer, error)
- func (c *Curl) ReadResponse(resp *http.Response) (serializer.Serializer, error)
- func (c *Curl) Send(request *http.Request) (serializer.Serializer, error)
- func (c *Curl) WithHttpClient(httpClient *http.Client) *Curl
- type DI
- type Event
- type EventDispatcher
- type Gorm
- func (g *Gorm) EnableConnectionPool(maxIdleConns int, maxOpenConns int, connMaxLifetime time.Duration) error
- func (g *Gorm) Open(dialector gorm.Dialector, config *gorm.Config) (err error)
- func (g *Gorm) OpenMySQL(dsn string) error
- func (g *Gorm) RegisterResolverConfig(config dbresolver.Config, tables ...interface{}) error
- func (g *Gorm) UseResolver(resolver *dbresolver.DBResolver) error
- type Handler
- type IProvider
- type JWT
- type Listener
- type LogLevel
- type Logger
- func (l *Logger) Debug(message string)
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(message string)
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Fatal(message string)
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Info(message string)
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) Log(level LogLevel, message string)
- func (l *Logger) Logf(level LogLevel, format string, a ...interface{})
- func (l *Logger) Panic(message string)
- func (l *Logger) Warn(message string)
- func (l *Logger) Warnf(format string, args ...interface{})
- type Mongo
- type MongoConfig
- type Named
- type Redis
- type Tracer
- type Validator
Constants ¶
const ( Sync = 0 Async = 1 )
Variables ¶
var (
EmptyResponse = errors.New("empty response")
)
var (
ErrTokenInvalid = errors.New("token is invalid")
)
Functions ¶
func Initialize ¶
func Initialize(provider IProvider)
Initialize sets the component provider instance
Types ¶
type Cache ¶
type Cache struct { Named // contains filtered or unexported fields }
Cache provide cache instance builder function
func (*Cache) Default ¶
func (c *Cache) Default() *cache.Cache
Default returns the default cache instance
func (*Cache) WithCleanupInterval ¶
WithCleanupInterval sets default cleanup interval for cache component
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
func NewContainer ¶
func NewContainer() *Container
func (*Container) EventDispatcher ¶
func (c *Container) EventDispatcher() *EventDispatcher
type Curl ¶
type Curl struct { Named // contains filtered or unexported fields }
Curl simple wrapper of http.Client
func (*Curl) Delete ¶
func (c *Curl) Delete(url string, body io.Reader) (serializer.Serializer, error)
Delete send delete request
func (*Curl) Get ¶
func (c *Curl) Get(url string) (serializer.Serializer, error)
Get send get request
func (*Curl) Post ¶
func (c *Curl) Post(url string, body io.Reader) (serializer.Serializer, error)
Post send post request
func (*Curl) PostFile ¶
func (c *Curl) PostFile(url string, files map[string]string, params map[string]string) (serializer.Serializer, error)
PostFile send post request with file
func (*Curl) Put ¶
func (c *Curl) Put(url string, body io.Reader) (serializer.Serializer, error)
Put send put request
func (*Curl) ReadResponse ¶
func (c *Curl) ReadResponse(resp *http.Response) (serializer.Serializer, error)
ReadResponse reads body from the *http.Response
func (*Curl) Send ¶
func (c *Curl) Send(request *http.Request) (serializer.Serializer, error)
Send return Response by http.Request
type DI ¶
type DI struct { Named // contains filtered or unexported fields }
DI implements dependencies injection component by *dig.Container
type EventDispatcher ¶
type EventDispatcher struct { Named // contains filtered or unexported fields }
func NewEventDispatcher ¶
func NewEventDispatcher() *EventDispatcher
func (*EventDispatcher) Has ¶
func (instance *EventDispatcher) Has(eventName string) bool
Has return event exist
func (*EventDispatcher) Listen ¶
func (instance *EventDispatcher) Listen(eventName string, handler Handler)
Listen register a sync event
func (*EventDispatcher) Register ¶
func (instance *EventDispatcher) Register(eventName string, listener Listener)
Register
func (*EventDispatcher) Trigger ¶
func (instance *EventDispatcher) Trigger(eventName string, params interface{})
Trigger make event trigger with given name and params
type Gorm ¶
func (*Gorm) EnableConnectionPool ¶
func (g *Gorm) EnableConnectionPool(maxIdleConns int, maxOpenConns int, connMaxLifetime time.Duration) error
EnableConnectionPool enables connection pool
func (*Gorm) RegisterResolverConfig ¶
func (g *Gorm) RegisterResolverConfig(config dbresolver.Config, tables ...interface{}) error
RegisterResolverConfig registers resolver configuration for current connection
func (*Gorm) UseResolver ¶
func (g *Gorm) UseResolver(resolver *dbresolver.DBResolver) error
UseResolver use resolver for gorm component.include set many db connection configuration with different model or table name
type IProvider ¶
type IProvider interface { Logger() *Logger Cache() *Cache Config() *Config Curl() *Curl Jwt() *JWT Tracer() *Tracer EventDispatcher() *EventDispatcher Redis() *Redis Validator() *Validator Gorm() *Gorm Cron() *Cron Register(components ...Component) Get(name string) (Component, bool) }
IProvider is a component provider
type JWT ¶
type JWT struct { Named // contains filtered or unexported fields }
JWT provide the jwt algorithm component
func (JWT) GenerateToken ¶
CreateToken 生成token
func (JWT) ParseToken ¶
ParseToken return jwt.MapClaims and error
func (*JWT) WithSignKey ¶
WithSignKey sets the jwt algorithm signature key
type Mongo ¶
func (*Mongo) Collection ¶
func (m *Mongo) Collection(name string, opts ...*options.CollectionOptions) *mongo.Collection
Collection use current database for the provide collection
type MongoConfig ¶
type MongoConfig struct { Address string // mongo address, like: mongodb://127.0.0.1:27017 Username string // username Password string Database string AuthSource string // default is admin Timeout time.Duration // default is 30 seconds }
MongoConfig represents the configuration of a MongoDB connection
type Redis ¶
type Redis struct { Named redis.UniversalClient }
type Tracer ¶
type Tracer struct { Named // contains filtered or unexported fields }
Tracer generate the uuid for per goroutine, use to mark user requests.
type Validator ¶
type Validator struct { Named // contains filtered or unexported fields }
func NewValidator ¶
func NewValidator() *Validator
func (*Validator) ValidateStruct ¶
ValidateStruct validate struct