config

package
v1.1.30 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: Apache-2.0 Imports: 24 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DefaultGroupName = "default" // Default configuration group name.
)
View Source
const (
	MemoryQueueName = "memory"
)
View Source
const (
	NsqQueueName = "nsq"
)
View Source
const (
	QueueCfgName = "queueConfig"
)
View Source
const (
	RabbitmqQueueName = "rabbitmq"
)
View Source
const (
	RedisQueueName = "redis"
)
View Source
const (
	RocketQueueName = "rocketmq"
)
View Source
const (
	UploadCfgName = "uploadConfig"
)

Variables

View Source
var (
	ExtendConfig interface{}
)
View Source
var JwtConfig = new(Jwt)

Functions

func GRedis added in v0.3.3

func GRedis() *cGRedis

GRedis 获取GRedis客户端

func QueueMemory

func QueueMemory() *cQueueMemory

func QueueNsq added in v0.3.4

func QueueNsq() *cQueueNsq

func QueueRabbit

func QueueRabbit() *cQueueRabbit

func QueueRedis

func QueueRedis() *cQueueRedis

func QueueRocket

func QueueRocket() *cQueueRocket

func Redis added in v0.3.4

func Redis() *cRedis

Redis 获取redis客户端

Types

type Cache

type Cache struct {
	Redis  *GRedisOptions
	Memory interface{}
}

func CacheConfig

func CacheConfig() *Cache

CacheConfig cache配置

func (*Cache) Setup

func (e *Cache) Setup(ctx context.Context, s *Settings) (storage.AdapterCache, error)

Setup 构造cache 顺序 redis > 其他 > memory

type Config

type Config struct {
	Jwt     map[string]*Jwt `yaml:"jwt"`
	Cache   *Cache          `yaml:"cache"`
	Queue   *Queue          `yaml:"queue"`
	Locker  *Locker         `yaml:"locker"`
	Extend  interface{}     `yaml:"extend"`
	Tus     tus.Config      `yaml:"tus"`
	Ws      *ws.Config      `yaml:"ws"`
	Metrics *Metrics        `yaml:"metrics"`
}

Config 配置集合

type Crypto added in v0.4.3

type Crypto struct {
	Enable    bool                      `json:"enable" yaml:"enable"`
	Algorithm string                    `json:"algorithm" yaml:"algorithm"`
	Rc4       security.Rc4CipherConfig  `json:"rc4" yaml:"rc4"`
	Rsa       security.RsaCiphersConfig `json:"rsa" yaml:"rsa"`
	Aes       security.AesCipherConfig  `json:"aes" yaml:"aes"`
}

type GRedisOptions added in v0.3.3

type GRedisOptions struct {
	Addr     string `yaml:"addr" json:"addr"`
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
	DB       int    `yaml:"db" json:"db"`
	Tls      *Tls   `yaml:"tls" json:"tls"`
}

func (*GRedisOptions) GetClientOptions added in v0.3.3

func (e *GRedisOptions) GetClientOptions(ctx context.Context, s *Settings) (*gredis.Config, error)

type Initialize

type Initialize interface {
	String() string
	Init(ctx context.Context, s *Settings) error
}

type Jwt

type Jwt struct {
	Secret      string `yaml:"secret" json:"secret"`
	SigningKey  string `yaml:"signingKey" json:"signing_key"`
	Timeout     int64  `yaml:"timeout" json:"timeout"`
	MaxRefresh  int64  `yaml:"maxRefresh" json:"max_refresh"`
	IdentityKey string `yaml:"identityKey" json:"identity_key"`
}

type Locker

type Locker struct {
	Redis *GRedisOptions
}

func LockerConfig

func LockerConfig() *Locker

func (*Locker) Empty

func (e *Locker) Empty() bool

Empty 空设置

func (*Locker) Setup

func (e *Locker) Setup(ctx context.Context, s *Settings) (storage.AdapterLocker, error)

Setup 启用顺序 redis > 其他 > memory

type Metrics added in v0.4.3

type Metrics struct {
	Enable          bool      `json:"enable" yaml:"enable"`
	Path            string    `json:"path" yaml:"path"`
	SlowTime        int32     `json:"slowTime" yaml:"slowTime"`
	RequestDuration []float64 `json:"requestDuration" yaml:"requestDuration"`
}

type NSQOptions

type NSQOptions struct {
	DialTimeout time.Duration `opt:"dial_timeout" default:"1s"`

	// Deadlines for network reads and writes
	ReadTimeout  time.Duration `opt:"read_timeout" min:"100ms" max:"5m" default:"60s"`
	WriteTimeout time.Duration `opt:"write_timeout" min:"100ms" max:"5m" default:"1s"`

	// Addresses is the local address to use when dialing an nsqd.
	Addresses []string `opt:"addresses"`

	// Duration between polling lookupd for new producers, and fractional jitter to add to
	// the lookupd pool loop. this helps evenly distribute requests even if multiple consumers
	// restart at the same time
	//
	// NOTE: when not using nsqlookupd, LookupdPollInterval represents the duration of time between
	// reconnection attempts
	LookupdPollInterval time.Duration `opt:"lookupd_poll_interval" min:"10ms" max:"5m" default:"60s"`
	LookupdPollJitter   float64       `opt:"lookupd_poll_jitter" min:"0" max:"1" default:"0.3"`

	// Maximum duration when REQueueing (for doubling of deferred requeue)
	MaxRequeueDelay     time.Duration `opt:"max_requeue_delay" min:"0" max:"60m" default:"15m"`
	DefaultRequeueDelay time.Duration `opt:"default_requeue_delay" min:"0" max:"60m" default:"90s"`

	// Maximum amount of time to backoff when processing fails 0 == no backoff
	MaxBackoffDuration time.Duration `opt:"max_backoff_duration" min:"0" max:"60m" default:"2m"`
	// Unit of time for calculating consumer backoff
	BackoffMultiplier time.Duration `opt:"backoff_multiplier" min:"0" max:"60m" default:"1s"`

	// Maximum number of times this consumer will attempt to process a message before giving up
	MaxAttempts uint16 `opt:"max_attempts" min:"0" max:"65535" default:"5"`

	// Duration to wait for a message from an nsqd when in a state where RDY
	// counts are re-distributed (e.g. max_in_flight < num_producers)
	LowRdyIdleTimeout time.Duration `opt:"low_rdy_idle_timeout" min:"1s" max:"5m" default:"10s"`
	// Duration to wait until redistributing RDY for an nsqd regardless of LowRdyIdleTimeout
	LowRdyTimeout time.Duration `opt:"low_rdy_timeout" min:"1s" max:"5m" default:"30s"`
	// Duration between redistributing max-in-flight to connections
	RDYRedistributeInterval time.Duration `opt:"rdy_redistribute_interval" min:"1ms" max:"5s" default:"5s"`

	// Identifiers sent to nsqd representing this client
	// UserAgent is in the spirit of HTTP (default: "<client_library_name>/<version>")
	ClientID  string `opt:"client_id"` // (defaults: short hostname)
	Hostname  string `opt:"hostname"`
	UserAgent string `opt:"user_agent"`

	// Duration of time between heartbeats. This must be less than ReadTimeout
	HeartbeatInterval time.Duration `opt:"heartbeat_interval" default:"30s"`
	// Integer percentage to sample the channel (requires nsqd 0.2.25+)
	SampleRate int32 `opt:"sample_rate" min:"0" max:"99"`

	Tls *Tls `yaml:"tls" json:"tls"`

	// Compression Settings
	Deflate      bool `opt:"deflate"`
	DeflateLevel int  `opt:"deflate_level" min:"1" max:"9" default:"6"`
	Snappy       bool `opt:"snappy"`

	// Size of the buffer (in bytes) used by nsqd for buffering writes to this connection
	OutputBufferSize int64 `opt:"output_buffer_size" default:"16384"`
	// Timeout used by nsqd before flushing buffered writes (set to 0 to disable).
	//
	// WARNING: configuring clients with an extremely low
	// (< 25ms) output_buffer_timeout has a significant effect
	// on nsqd CPU usage (particularly with > 50 clients connected).
	OutputBufferTimeout time.Duration `opt:"output_buffer_timeout" default:"250ms"`

	// Maximum number of messages to allow in flight (concurrency knob)
	MaxInFlight int `opt:"max_in_flight" min:"0" default:"1"`

	// The server-side message timeout for messages delivered to this client
	MsgTimeout time.Duration `opt:"msg_timeout" min:"0"`

	// secret for nsqd authentication (requires nsqd 0.2.29+)
	AuthSecret string `opt:"auth_secret"`
}

func (*NSQOptions) GetNsqOptions added in v0.3.4

func (e *NSQOptions) GetNsqOptions(ctx context.Context, s *Settings) (*nsq.Config, error)

type Queue

type Queue struct {
	CfgList []QueueInitialize
}

func QueueConfig

func QueueConfig() *Queue

func (*Queue) Init added in v0.3.4

func (q *Queue) Init(ctx context.Context, s *Settings) error

func (*Queue) String added in v0.3.4

func (q *Queue) String() string

type QueueInitialize added in v0.3.4

type QueueInitialize interface {
	Initialize
	GetQueue(ctx context.Context) (storage.AdapterQueue, error)
}

type RabbitOptions

type RabbitOptions struct {
	Dsn      string `yaml:"dsn" json:"dsn"`
	Addr     string `yaml:"addr" json:"addr"`
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
	// Vhost specifies the namespace of permissions, exchanges, queues and
	// bindings on the server.  Dial sets this to the path parsed from the URL.
	Vhost             string        `yaml:"vhost" json:"vhost"`
	ChannelMax        int           `yaml:"channelMax" json:"channel_max"` // 0 max channels means 2^16 - 1
	FrameSize         int           `yaml:"frameSize" json:"frame_size"`   // 0 max bytes means unlimited
	Heartbeat         time.Duration `yaml:"heartbeat" json:"heartbeat"`    // less than 1s uses the server's interval
	ReconnectInterval int           `yaml:"reconnectInterval" json:"reconnectInterval"`
	// TLSClientConfig specifies the client configuration of the TLS connection
	// when establishing a tls transport.
	// If the URL uses an amqps scheme, then an empty tls.Config with the
	// ServerName from the URL is used.
	Tls *Tls             `json:"tls" yaml:"tls"`
	Cfg *rabbitmq.Config `json:"cfg" yaml:"cfg"`
	// log
	LogPath   string `yaml:"logPath" json:"log_path"`
	LogFile   string `yaml:"logFile" json:"log_file"`
	LogLevel  string `yaml:"logLevel" json:"log_level"`
	LogStdout bool   `yaml:"logStdout" json:"log_stdout"`
}

func (*RabbitOptions) GetCfg added in v0.3.4

func (e *RabbitOptions) GetCfg() *rabbitmq.Config

func (*RabbitOptions) GetDsn

func (e *RabbitOptions) GetDsn() string

func (*RabbitOptions) GetRabbitOptions

func (e *RabbitOptions) GetRabbitOptions(ctx context.Context, s *Settings) (*RabbitOptions, error)

func (*RabbitOptions) GetReconnectInterval added in v0.3.4

func (e *RabbitOptions) GetReconnectInterval() int

type RedisConnectOptions

type RedisConnectOptions struct {
	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"`
	Tls        *Tls   `yaml:"tls" json:"tls"`
	MaxRetries int    `yaml:"max_retries" json:"max_retries"`
}

func (*RedisConnectOptions) GetRedisOptions

func (e *RedisConnectOptions) GetRedisOptions(ctx context.Context, s *Settings) (*redis.Options, error)

type RocketOptions

type RocketOptions struct {
	Urls []string `yaml:"urls" json:"urls"`
	*primitive.Credentials
	LogPath   string `yaml:"logPath" json:"log_path"`
	LogFile   string `yaml:"logFile" json:"log_file"`
	LogLevel  string `yaml:"logLevel" json:"log_level"`
	LogStdout bool   `yaml:"logStdout" json:"log_stdout"`
}

func (*RocketOptions) GetRocketOptions

func (e *RocketOptions) GetRocketOptions(ctx context.Context, s *Settings) (*RocketOptions, error)

type Settings

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

Settings 兼容原先的配置结构

func Setting added in v0.2.7

func Setting() *Settings

func (*Settings) Bootstrap added in v0.2.7

func (e *Settings) Bootstrap(ctx context.Context, fs ...Initialize)

Bootstrap 载入启动配置文件

func (*Settings) Cfg added in v0.2.8

func (e *Settings) Cfg() *gcfg.Config

func (*Settings) Config

func (e *Settings) Config() *Config

func (*Settings) GetJwt added in v0.3.2

func (e *Settings) GetJwt(module string) *Jwt

func (*Settings) GetTus added in v0.3.8

func (e *Settings) GetTus() tus.Config

func (*Settings) Init

func (e *Settings) Init(ctx context.Context)

func (*Settings) SetCfg added in v0.3.0

func (e *Settings) SetCfg(cf *gcfg.Config) *Settings

func (*Settings) SetConfig added in v0.2.8

func (e *Settings) SetConfig(c Config) *Settings

func (*Settings) SetJwt added in v0.3.2

func (e *Settings) SetJwt(module string, jwt *Jwt) *Settings

func (*Settings) SetSrv added in v0.3.1

func (e *Settings) SetSrv(srv *ghttp.Server) *Settings

func (*Settings) Srv added in v0.2.8

func (e *Settings) Srv() *ghttp.Server

type Tls

type Tls struct {
	Cert string `yaml:"cert" json:"cert"`
	Key  string `yaml:"key" json:"key"`
	Ca   string `yaml:"ca" json:"ca"`
}

type Upload added in v0.3.8

type Upload struct{}

func UploadConfig added in v0.3.8

func UploadConfig() *Upload

func (*Upload) Init added in v0.3.8

func (q *Upload) Init(ctx context.Context, s *Settings) error

func (*Upload) String added in v0.3.8

func (q *Upload) String() string

Jump to

Keyboard shortcuts

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