Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ApplicationConfig = new(Application)
var CacheConfig = new(Cache)
CacheConfig cache配置
var (
ExtendConfig interface{}
)
var GenConfig = new(Gen)
var JwtConfig = new(Jwt)
var LoggerConfig = new(Logger)
var QueueConfig = new(Queue)
var SslConfig = new(Ssl)
Functions ¶
Types ¶
type Application ¶
type Cache ¶
type Cache struct {
Redis *RedisOptions
Memory interface{}
}
Cache selects the cache backend.
Leaving every field unset is a valid configuration and yields the in-memory cache, so a single instance runs with nothing beside it. Redis is opt-in and only for deployments that run more than one instance.
func (Cache) Open ¶ added in v1.8.0
Open builds the configured cache. Order: redis > memory.
A redis section that cannot be reached is an error rather than a fallback: falling back would hand an operator who asked for a shared cache one that is not shared, and the symptom would only appear later, under load.
func (Cache) Setup
deprecated
func (e Cache) Setup() (storage.AdapterCache, error)
Setup builds the cache adapter. Order: redis > memory.
Deprecated: use Open, which returns the current contract. This returns the older AdapterCache so that existing call sites keep working; storage.Cache can report a miss and takes a context, neither of which survives the bridge.
type Config ¶
type Config struct {
Application *Application `yaml:"application"`
Ssl *Ssl `yaml:"ssl"`
Logger *Logger `yaml:"logger"`
Jwt *Jwt `yaml:"jwt"`
Database *Database `yaml:"database"`
Databases *map[string]*Database `yaml:"databases"`
Gen *Gen `yaml:"gen"`
Cache *Cache `yaml:"cache"`
Queue *Queue `yaml:"queue"`
Extend interface{} `yaml:"extend"`
}
Config 配置集合
type DBResolverConfig ¶
type Logger ¶
type Logger struct {
Type string `yaml:"type"`
Adapter string `yaml:"adapter"`
Path string `yaml:"path"`
Level string `yaml:"level"`
Stdout string `yaml:"stdout"`
Encoder string `yaml:"encoder"`
EnableCaller bool `yaml:"enableCaller"`
EnabledDB bool `yaml:"enableddb"`
Cap uint `yaml:"cap"`
Rotation *RotationConfig `yaml:"rotation"`
}
type Queue ¶ added in v1.6.0
type Queue struct {
Redis *RedisQueue
Memory *QueueMemory
}
Queue selects the queue backend, on the same terms as Cache: memory unless a redis section says otherwise.
func (Queue) Open ¶ added in v1.8.0
Open builds the configured queue. Order: redis > memory.
As with Cache.Open, an unreachable redis section is an error rather than a fallback to a queue that other instances cannot see.
func (Queue) Setup
deprecated
added in
v1.6.0
func (e Queue) Setup() (storage.AdapterQueue, error)
Setup builds the queue adapter. Order: redis > memory.
Deprecated: use Open, which returns the current contract.
Note that the two branches do not behave identically, because the memory one stays on the older implementation: there, Register starts consuming on its own and retries a failed message three times, while the bridged Redis queue only consumes once Run is called. A call site that registers without running works on memory and silently consumes nothing on Redis.
type QueueMemory ¶ added in v1.6.0
type QueueMemory struct {
PoolSize uint
}
type RedisOptions ¶ added in v1.8.0
type RedisOptions struct {
URL string `yaml:"url" json:"url"`
Network string `yaml:"network" json:"network"`
Addr string `yaml:"addr" json:"addr"`
Username string `yaml:"username" json:"username"`
Password string `yaml:"password" json:"password"`
DB int `yaml:"db" json:"db"`
PoolSize int `yaml:"pool_size" json:"pool_size"`
MaxRetries int `yaml:"max_retries" json:"max_retries"`
Tls *Tls `yaml:"tls" json:"tls"`
}
RedisOptions describes how to reach a Redis server.
Set URL, which understands redis:// and rediss:// and is what a managed provider hands out, or fill in the individual fields. URL wins when both are present.
The json names are what the configuration file is keyed on, and they match the ones this repository used before Redis support was removed, so an older settings file still applies.
func (RedisOptions) Client ¶ added in v1.8.0
Client connects and verifies the server answers, so that a wrong address fails the boot rather than the first request that needs the cache.
The returned client is shared with every other caller naming the same destination, and is not closed by this package.
func (RedisOptions) GetRedisOptions ¶ added in v1.8.0
func (e RedisOptions) GetRedisOptions() (*goredis.Options, error)
GetRedisOptions converts the configuration into client options.
type RedisQueue ¶ added in v1.8.0
type RedisQueue struct {
RedisOptions `yaml:",inline"`
Group string `yaml:"group" json:"group"`
KeyPrefix string `yaml:"key_prefix" json:"key_prefix"`
MaxAttempts int `yaml:"max_attempts" json:"max_attempts"`
// In seconds, because a settings file cannot express a time.Duration.
ClaimMinIdleSeconds int `yaml:"claim_min_idle_seconds" json:"claim_min_idle_seconds"`
}
RedisQueue adds the consumer-group settings to a Redis connection.
The json names are what a settings file is keyed on. For what each setting means and what a zero value falls back to, see redisstore.QueueOptions; options absent here can only be set in code.
type RotationConfig ¶ added in v1.6.4
type RotationConfig struct {
MaxSize int `yaml:"maxSize"`
MaxAge int `yaml:"maxAge"`
MaxBackups int `yaml:"maxBackups"`
Compress bool `yaml:"compress"`
}
RotationConfig 日志轮转配置