config

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Getenv

func Getenv(name string) string

Getenv 获取环境变量

func LoadIni

func LoadIni(conf interface{}, filePath string) error

Load 加载ini配置

func LoadJson

func LoadJson(conf interface{}, filePath string) error

Load 加载json配置

func LoadYaml

func LoadYaml(conf interface{}, filePath string) error

Load 加载yaml配置

Types

type Config

type Config struct {
	// 服务名称
	ServiceName string

	// 服务端口号
	ServicePort int

	// 响应日志最大长度
	MaxResponseLogSize int

	// 日志路径
	LogPath string

	// jwt的key
	JwtSignKey []byte

	// trace header key
	TraceHeader string
	// contains filtered or unexported fields
}

Config 系统配置项

func NewInstance

func NewInstance() *Config

init 通过读取环境变量初始化系统配置

func (*Config) Mns

func (config *Config) Mns() *MnsConfig

Mns config

func (*Config) Mysql

func (config *Config) Mysql() *MysqlOptions

Mysql config

func (*Config) Redis

func (config *Config) Redis() *RedisOptions

Redis config

type MnsConfig

type MnsConfig struct {
	Url             string `json:"url"`
	AccessKeyId     string `json:"access_key_id"`
	AccessKeySecret string `json:"access_key_secret"`
}

MnsConfig 阿里云MNS 配置项

type MysqlOptions

type MysqlOptions struct {
	// auto connect
	AutoConnect bool

	// database name
	Name string

	// host
	Host string

	// port, default 3306
	Port int

	// user, default root
	User string

	// password
	Password string

	// log mode
	LogMode bool

	// MaxIdleConnections, default 10
	MaxIdleConnections int

	// MaxOpenConnections, default 40
	MaxOpenConnections int
}

MysqlOptions

func (MysqlOptions) Dsn

func (options MysqlOptions) Dsn() string

Dsn return mysql dsn

type RedisOptions

type RedisOptions struct {
	// AutoConnect
	AutoConnect bool

	// host
	Host string

	// port, default 6379
	Port int

	// auth
	Auth string

	// pool size, default 100
	PoolSize int

	// max retries, default 3
	MaxRetries int

	// timeout, default 10 seconds
	IdleTimeout time.Duration
}

RedisOptions redis配置

func (*RedisOptions) Options

func (conf *RedisOptions) Options() *redis.Options

Options get redis options

Jump to

Keyboard shortcuts

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