config

package
v1.6.9 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DatabaseConfig  = new(Database)
	DatabasesConfig = make(map[string]*Database)
)
View Source
var AmqpConfig = new(Amqp)
View Source
var ApplicationConfig = new(Application)
View Source
var BlockChainConfig = new(BlockChain)
View Source
var CacheConfig = new(Cache)

CacheConfig cache配置

View Source
var (
	ExtendConfig interface{}
)
View Source
var FileStoreConfig = new(FileStore)
View Source
var GenConfig = new(Gen)
View Source
var JwtConfig = new(Jwt)
View Source
var LbsConfig = new(Lbs)
View Source
var LockerConfig = new(Locker)
View Source
var LoggerConfig = new(Logger)
View Source
var MailConfig = new(Mail)
View Source
var ModerationConfig = new(Moderation)
View Source
var PaymentConfig = new(Payment)
View Source
var QueueConfig = new(Queue)
View Source
var SecretConfig = new(Secret)
View Source
var SmsConfig = new(Sms)
View Source
var SslConfig = new(Ssl)
View Source
var WeChatConfig = new(WeChat)

Functions

func Setup

func Setup(s source.Source,
	fs ...func())

Setup 载入配置文件

Types

type AliyunAudit added in v1.4.11

type AliyunAudit struct {
	AccessId     string `json:"access_id" yaml:"access_id"`
	AccessSecret string `json:"access_secret" yaml:"access_secret"`
	Region       string `json:"region" yaml:"region"`
	CallbackUrl  string `json:"callback_url" yaml:"callback_url"`
}

type AliyunFile added in v1.4.11

type AliyunFile struct {
	AccessId     string `json:"access_id" yaml:"access_id"`
	AccessSecret string `json:"access_secret" yaml:"access_secret"`
	Bucket       string `json:"bucket" yaml:"bucket"`
	Endpoint     string `json:"endpoint" yaml:"endpoint"`
	Region       string `json:"region" yaml:"region"`
}

type AliyunSms added in v1.4.11

type AliyunSms struct {
	Addr         string `json:"addr" yaml:"addr"`
	AccessId     string `json:"access_id" yaml:"access_id"`
	AccessSecret string `json:"access_secret" yaml:"access_secret"`
	Region       string `json:"region" yaml:"region"`
	Signature    string `json:"signature" yaml:"signature"`
}

type Amap added in v1.3.30

type Amap struct {
	Addr      string `json:"addr" yaml:"addr"`
	SecretKey string `json:"secret_key" yaml:"secret_key"`
}

type Amqp added in v1.3.30

type Amqp struct {
	Rocket *Rocket `json:"rocket,omitempty" yaml:"rocket"`
	Rabbit *Rabbit `json:"rabbit,omitempty" yaml:"rabbit"`
}

type Application

type Application struct {
	Mode          string `json:"mode,omitempty" yaml:"mode"`
	Name          string `json:"name,omitempty" yaml:"name"`
	Host          string `json:"host,omitempty" yaml:"host"`
	Port          int    `json:"port,omitempty" yaml:"port"`
	JwtSecret     string `json:"jwt_secret,omitempty" yaml:"jwt_secret"`
	ReadTimeout   int    `json:"read_timeout,omitempty" yaml:"read_timeout"`
	WriterTimeout int    `json:"writer_timeout,omitempty" yaml:"writer_timeout"`
	EnableDP      bool   `json:"enabled_data_permission,omitempty" yaml:"enabled_data_permission"`
	DemoMessage   string `json:"demo_message,omitempty" yaml:"demo_message"`
}

type BlockChain added in v1.3.30

type BlockChain struct {
	Broker *BrokerConnectOptions
}

type BrokerConnectOptions added in v1.3.30

type BrokerConnectOptions struct {
	MintAddr     string `json:"mint_addr" yaml:"mint_addr"`
	CallbackAddr string `yaml:"callback_addr" json:"callback_addr"`
	ClientId     string `yaml:"client_id" json:"client_id"`
	FilePath     string `yaml:"file_path" json:"file_path"`
	Addr         string `yaml:"addr" json:"addr"`
}

type Cache

type Cache struct {
	Redis  *RedisConnectOptions `json:"redis" yaml:"redis"`
	Memory interface{}
}

func (Cache) Setup

func (e Cache) Setup() storage.AdapterCache

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

type Config

type Config struct {
	Application *Application          `json:"application" yaml:"application"`
	Secret      *Secret               `json:"secret" yaml:"secret"`
	Ssl         *Ssl                  `json:"ssl" yaml:"ssl"`
	Logger      *Logger               `json:"logger" yaml:"logger"`
	Jwt         *Jwt                  `json:"jwt" yaml:"jwt"`
	Database    *Database             `json:"database" yaml:"database"`
	Databases   *map[string]*Database `json:"databases" yaml:"databases"`
	Gen         *Gen                  `json:"gen" yaml:"gen"`
	Cache       *Cache                `json:"cache" yaml:"cache"`
	Queue       *Queue                `json:"queue" yaml:"queue"`
	Locker      *Locker               `json:"locker" yaml:"locker"`
	Lbs         *Lbs                  `json:"lbs,omitempty" yaml:"lbs"`
	FileStore   *FileStore            `json:"file_store,omitempty" yaml:"file_store"`
	Moderation  *Moderation           `json:"moderation,omitempty" yaml:"moderation"`
	Sms         *Sms                  `json:"sms,omitempty" yaml:"sms"`
	Mail        *Mail                 `json:"mail" yaml:"mail"`
	Amqp        *Amqp                 `json:"mq,omitempty" yaml:"mq"`
	WeChat      *WeChat               `json:"wechat,omitempty" yaml:"wechat"`
	Payment     *Payment              `json:"payment,omitempty" yaml:"payment"`
	Extend      interface{}           `json:"extend" yaml:"extend"`
}

Config 配置集合

type DBResolverConfig

type DBResolverConfig struct {
	Sources  []string
	Replicas []string
	Policy   string
	Tables   []string
}

type Database

type Database struct {
	Driver          string             `json:"driver,omitempty" yaml:"driver"`
	Source          string             `json:"source,omitempty" yaml:"source"`
	ConnMaxIdleTime int                `json:"conn_max_idle_time,omitempty" yaml:"conn_max_idle_time"`
	ConnMaxLifetime int                `json:"conn_max_lifetime,omitempty" yaml:"conn_max_lifetime"`
	MaxIdleConns    int                `json:"max_idle_conns,omitempty" yaml:"max_idle_conns"`
	MaxOpenConns    int                `json:"max_open_conns,omitempty" yaml:"max_open_conns"`
	Registers       []DBResolverConfig `json:"registers,omitempty" yaml:"registers"`
}

type FileStore added in v1.3.30

type FileStore struct {
	Tencent *TencentFile `json:"tencent" yaml:"tencent"`
	Aliyun  *AliyunFile  `json:"aliyun" yaml:"aliyun"`
	Huawei  *HuaweiFile  `json:"huawei" yaml:"huawei"`
}

type Gen

type Gen struct {
	DBName    string
	FrontPath string
}

type HuaweiAudit added in v1.4.11

type HuaweiAudit struct {
	AccessKey   string `json:"access_key" yaml:"access_key"`
	SecretKey   string `json:"secret_key" yaml:"secret_key"`
	Region      string `json:"region" yaml:"region"`
	CallbackUrl string `json:"callback_url" yaml:"callback_url"`
}

type HuaweiFile added in v1.4.11

type HuaweiFile struct {
	AccessKey string `json:"access_key" yaml:"access_key"`
	SecretKey string `json:"secret_key" yaml:"secret_key"`
	Bucket    string `json:"bucket" yaml:"bucket"`
	Endpoint  string `json:"endpoint" yaml:"endpoint"`
	Region    string `json:"region" yaml:"region"`
}

type Jwt

type Jwt struct {
	Secret  string `json:"secret,omitempty" yaml:"secret"`
	Timeout int64  `json:"timeout,omitempty" yaml:"timeout"`
}

type Lbs added in v1.3.30

type Lbs struct {
	Amap *Amap `json:"amap"`
}

type Locker

type Locker struct {
	Redis *RedisConnectOptions `json:"redis" yaml:"redis"`
}

func (Locker) Empty

func (e Locker) Empty() bool

Empty 空设置

func (Locker) Setup

func (e Locker) Setup() storage.AdapterLocker

Setup 启用顺序 redis > 其他 > memory

type Logger

type Logger struct {
	Type      string `json:"type,omitempty" yaml:"type"`
	Path      string `json:"path,omitempty" yaml:"path"`
	Level     string `json:"level,omitempty" yaml:"level"`
	Stdout    string `json:"stdout,omitempty" yaml:"stdout"`
	EnabledDB bool   `json:"enabled_db,omitempty" yaml:"enabled_db"`
	Cap       uint   `json:"cap,omitempty" yaml:"cap"`
}

func (Logger) Setup

func (e Logger) Setup()

Setup 设置logger

type Mail added in v1.3.30

type Mail struct {
	Smtp *SmtpConnectOptions `json:"smtp" yaml:"smtp"`
}

type Moderation added in v1.4.11

type Moderation struct {
	Tencent *TencentAudit `json:"tencent" yaml:"tencent"`
	Aliyun  *AliyunAudit  `json:"aliyun" yaml:"aliyun"`
	Huawei  *HuaweiAudit  `json:"huawei" yaml:"huawei"`
}

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

func (e NSQOptions) GetNSQOptions() (*nsq.Config, error)

type Payment added in v1.4.9

type Payment struct {
	WeChatPay *WeChatPayOption `yaml:"wechat" json:"wechat"`
}

type Queue

type Queue struct {
	Redis  *QueueRedis  `json:"redis" yaml:"redis"`
	Memory *QueueMemory `json:"memory" yaml:"memory"`
	NSQ    *QueueNSQ    `json:"nsq" yaml:"nsq"`
}

func (Queue) Empty

func (e Queue) Empty() bool

Empty 空设置

func (Queue) Setup

func (e Queue) Setup() storage.AdapterQueue

Setup 启用顺序 redis > 其他 > memory

type QueueMemory

type QueueMemory struct {
	PoolSize uint `json:"pool_size" yaml:"pool_size"`
}

type QueueNSQ

type QueueNSQ struct {
	NSQOptions
	ChannelPrefix string `json:"channel_prefix" yaml:"channel_prefix"`
}

type QueueRedis

type QueueRedis struct {
	RedisConnectOptions
	Producer *redisqueue.ProducerOptions
	Consumer *redisqueue.ConsumerOptions
}

type Rabbit added in v1.5.7

type Rabbit struct {
	Addr      string `json:"addr" yaml:"addr"`
	AccessKey string `json:"access_key" yaml:"access_key"`
	SecretKey string `json:"secret_key" yaml:"secret_key"`
	Namespace string `json:"namespace" yaml:"namespace"`
}

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() *redis.Options

type Rocket added in v1.3.30

type Rocket struct {
	Addr       string `json:"addr" yaml:"addr"`
	AccessKey  string `json:"access_key" yaml:"access_key"`
	SecretKey  string `json:"secret_key" yaml:"secret_key"`
	Namespace  string `json:"namespace" yaml:"namespace"`
	InstanceId string `json:"instance_id" yaml:"instance_id"`
	ProducerId string `json:"producer_id" yaml:"producer_id"`
	ConsumerId string `json:"consumer_id" yaml:"consumer_id"`
}

type Secret added in v1.4.1

type Secret struct {
	AppId         string `json:"app_id" yaml:"app_id"`
	AppSecret     string `json:"app_secret" yaml:"app_secret"`
	AesSecret     string `json:"aes_secret,omitempty" yaml:"aes_secret"`
	RsaPubKey     string `json:"rsa_pub_key" yaml:"rsa_pub_key"`
	RsaPrivateKey string `json:"rsa_private_key" yaml:"rsa_private_key"`
}

type Settings

type Settings struct {
	Settings Config `yaml:"settings"`
	// contains filtered or unexported fields
}

Settings 兼容原先的配置结构

func (*Settings) Init

func (e *Settings) Init()

func (*Settings) OnChange

func (e *Settings) OnChange()

type Sms added in v1.3.30

type Sms struct {
	Tencent *TencentSms `json:"tencent" yaml:"tencent"`
	Aliyun  *AliyunSms  `json:"aliyun" yaml:"aliyun"`
}

type SmtpConnectOptions added in v1.3.30

type SmtpConnectOptions struct {
	Addr     string `yaml:"addr" json:"addr"`
	Username string `yaml:"username" json:"username"`
	Password string `yaml:"password" json:"password"`
	From     string `yaml:"from" json:"from"`
}

type Ssl

type Ssl struct {
	KeyStr string
	Pem    string
	Enable bool
	Domain string
}

type TencentAudit added in v1.4.11

type TencentAudit struct {
	AccessKey   string `json:"access_key" yaml:"access_key"`
	SecretKey   string `json:"secret_key" yaml:"secret_key"`
	Region      string `json:"region" yaml:"region"`
	CosUrl      string `json:"cos_url" yaml:"cos_url"`
	CiUrl       string `json:"ci_url" yaml:"ci_url"`
	CallbackUrl string `json:"callback_url" yaml:"callback_url"`
}

type TencentFile added in v1.4.11

type TencentFile struct {
	AccessKey string `json:"access_key" yaml:"access_key"`
	SecretKey string `json:"secret_key" yaml:"secret_key"`
	CosUrl    string `json:"cos_url" yaml:"cos_url"`
	CiUrl     string `json:"ci_url" yaml:"ci_url"`
	Region    string `json:"region" yaml:"region"`
}

type TencentSms added in v1.4.11

type TencentSms struct {
	SecretId  string `json:"secret_id" yaml:"secret_id"`
	SecretKey string `json:"secret_key" yaml:"secret_key"`
	AppId     string `json:"app_id" yaml:"app_id"`
	AppKey    string `json:"app_key" yaml:"app_key"`
	Region    string `json:"region" yaml:"region"`
	Addr      string `json:"addr" yaml:"addr"`
	Alg       string `json:"alg" yaml:"alg"`
	Signature string `json:"signature" yaml:"signature"`
}

type Tls

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

type WeChat added in v1.3.30

type WeChat struct {
	Open *WeChatOption `json:"open,omitempty" yaml:"open"`
	Mp   *WeChatOption `json:"mp,omitempty" yaml:"mp"`
}

type WeChatOption added in v1.3.30

type WeChatOption struct {
	AppId        string `json:"app_id" yaml:"app_id"`
	AppSecret    string `json:"app_secret" yaml:"app_secret"`
	AesKey       string `json:"aes_key" yaml:"aes_key"`
	Token        string `json:"token" yaml:"token"`
	CallbackAddr string `json:"callback_addr" yaml:"callback_addr" yaml:"callback_addr"`
}

type WeChatPayOption added in v1.4.9

type WeChatPayOption struct {
	MerchantId     string `yaml:"merchant_id" json:"merchant_id"`
	AppId          string `yaml:"app_id" json:"app_id"`
	PrivateKeyPath string `yaml:"private_key_path" json:"private_key_path"`
	SerialNumber   string `yaml:"serial_no" json:"serial_no"`
	ApiV3Key       string `yaml:"api_v3_key" json:"api_v3_key"`
	CallbackAddr   string `yaml:"callback_addr" json:"callback_addr"`
	WeChatCertPath string `yaml:"wechat_cert_path" json:"wechat_cert_path"`
}

Jump to

Keyboard shortcuts

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