config

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsApolloEnable

func IsApolloEnable() bool

IsApolloEnable is apollo enable

func IsNil

func IsNil() bool

IsNil check config init status

func LoadCustomFromApollo added in v0.9.3

func LoadCustomFromApollo(customCfg interface{}) error

LoadCustomFromFile Load custom config from apollo, save to custom config

func LoadCustomFromFile

func LoadCustomFromFile(fileName string, customCfg interface{}) error

LoadCustomFromFile Load custom config from file, save to custom config

func LoadFileEnvKey

func LoadFileEnvKey() string

LoadFileEnvKey load file env key

func LoadFromApollo added in v0.9.3

func LoadFromApollo()

func LoadFromEnvFile

func LoadFromEnvFile()

LoadEnvFile Load config from the file that path is saved in os env.

func LoadFromFile

func LoadFromFile(fileName string) error

LoadFromFile from file

func NotNil

func NotNil() bool

NotNil check config not nil

func SetLoadFileEnvKey

func SetLoadFileEnvKey(key string)

SetLoadFileEnvKey set env var name for read the config file path, default:PG_CONF_FILE

Types

type ApolloConfig

type ApolloConfig struct {
	Enable   bool        `yaml:"enable"`
	Settings apollo.Conf `yaml:"settings"`
}

ApolloConfig apollo config

type AppConfig

type AppConfig struct {
	Name    string
	Version string
	Env     string
}

AppConfig application config

func App

func App() AppConfig

App app config

type Config

type Config struct {
	App       AppConfig
	Databases []*DatabaseConfig `yaml:"databases,flow"`
	OpenAPI   OpenAPIConfig     `yaml:"openapi"`
	Server    ServerConfig      `yaml:"server"`
	Logging   LoggingConfig     `yaml:"logging"`
	Mails     []MailConfig      `yaml:"mail,flow"`
	Apollo    ApolloConfig      `yaml:"apollo"`
	Redis     RedisConfig       `yaml:"redis"`
}

Config all config

type DatabaseConfig

type DatabaseConfig struct {
	Dialect     string `yaml:"dialect"`
	DSN         string `yaml:"dsn"`
	MaxIdle     int    `yaml:"maxIdle"`
	MaxOpen     int    `yaml:"maxOpen"`
	MaxLifetime int    `yaml:"maxLifetime"`
	ShowSQL     bool   `yaml:"showSQL"`
}

DatabaseConfig db config

func Database

func Database() *DatabaseConfig

Database first database config

func Databases

func Databases() []*DatabaseConfig

Databases Multi Database config

type LoggingConfig

type LoggingConfig struct {
	Level        uint32
	ReportCaller bool `yaml:"report-caller"`
	NoColors     bool `yaml:"no-colors"`
	CallerFirst  bool `yaml:"caller-first"`
}

LoggingConfig log config

func Logging

func Logging() LoggingConfig

Logging log config

type MailConfig

type MailConfig struct {
	IMAPAddr string `yaml:"imap-addr"`
	SMTPAddr string `yaml:"smtp-addr"`
	TLS      bool   `yaml:"tls"`
	Username string
	Password string
}

MailConfig mail config

func Mails

func Mails() []MailConfig

Mails mail settings

type OpenAPIConfig

type OpenAPIConfig struct {
	Enabled  bool     `yaml:"enabled"`
	Host     string   `yaml:"host"`
	BasePath string   `yaml:"basePath"`
	Schemas  []string `yaml:"schemas"`
	Spec     struct {
		Title       string
		Description string `yaml:"desc"`
		Contact     struct {
			Name  string
			Email string
			URL   string
		} `yaml:"contact"`
		License struct {
			Name string
			URL  string
		} `yaml:"license"`
		Version string
	}
	Tags []OpenapiTagConfig `yaml:",flow"`
	UI   OpenapiUIConfig    `yaml:"ui"`
}

OpenAPIConfig open api config

func Openapi

func Openapi() OpenAPIConfig

OpenAPI openapi config

type OpenapiTagConfig

type OpenapiTagConfig struct {
	Name        string
	Description string `yaml:"desc"`
}

OpenapiTagConfig openapi tag

type OpenapiUIConfig

type OpenapiUIConfig struct {
	API        string `yaml:"api"`
	Dist       string `yaml:"dist"`
	Entrypoint string `yaml:"entrypoint"`
}

OpenapiUIConfig swagger ui config

type RedisClusterConfig

type RedisClusterConfig struct {
	Addrs []string

	// The maximum number of retries before giving up. Command is retried
	// on network errors and MOVED/ASK redirects.
	// Default is 8 retries.
	MaxRedirects int

	// Enables read-only commands on slave nodes.
	ReadOnly bool
	// Allows routing read-only commands to the closest master or slave node.
	// It automatically enables ReadOnly.
	RouteByLatency bool
	// Allows routing read-only commands to the random master or slave node.
	// It automatically enables ReadOnly.
	RouteRandomly bool
}

RedisClusterConfig 集群模式配置

type RedisCommonConfig

type RedisCommonConfig struct {
	// Use the specified Username to authenticate the current connection
	// with one of the connections defined in the ACL list when connecting
	// to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
	Username string `yaml:"username"`
	// Optional password. Must match the password specified in the
	// requirepass server configuration option (if connecting to a Redis 5.0 instance, or lower),
	// or the User Password when connecting to a Redis 6.0 instance, or greater,
	// that is using the Redis ACL system.
	Password string `yaml:"password"`

	// Database to be selected after connecting to the server.
	DB int `yaml:"db"`

	// Maximum number of retries before giving up.
	// Default is to not retry failed commands.
	MaxRetries int `yaml:"max-retries"`
	// Minimum backoff between each retry.
	// Default is 8 milliseconds; -1 disables backoff.
	MinRetryBackoff string `yaml:"min-retry-backoff"`
	// Maximum backoff between each retry.
	// Default is 512 milliseconds; -1 disables backoff.
	MaxRetryBackoff string `yaml:"max-retry-backoff"`

	// Dial timeout for establishing new connections.
	// Default is 5 seconds.
	DialTimeout string `yaml:"dial-timeout"`
	// Timeout for socket reads. If reached, commands will fail
	// with a timeout instead of blocking. Use value -1 for no timeout and 0 for default.
	// Default is 3 seconds.
	ReadTimeout string `yaml:"read-timeout"`
	// Timeout for socket writes. If reached, commands will fail
	// with a timeout instead of blocking.
	// Default is ReadTimeout.
	WriteTimeout string `yaml:"write-timeout"`

	// Maximum number of socket connections.
	// Default is 10 connections per every CPU as reported by runtime.NumCPU.
	PoolSize int `yaml:"pool-size"`
	// Minimum number of idle connections which is useful when establishing
	// new connection is slow.
	MinIdleConns int `yaml:"min-idle-conns"`
	// Connection age at which client retires (closes) the connection.
	// Default is to not close aged connections.
	MaxConnAge string `yaml:"max-conn-age"`
	// Amount of time client waits for connection if all connections
	// are busy before returning an error.
	// Default is ReadTimeout + 1 second.
	PoolTimeout string `yaml:"pool-timeout"`
	// Amount of time after which client closes idle connections.
	// Should be less than server's timeout.
	// Default is 5 minutes. -1 disables idle timeout check.
	IdleTimeout string `yaml:"idle-timeout"`
	// Frequency of idle checks made by idle connections reaper.
	// Default is 1 minute. -1 disables idle connections reaper,
	// but idle connections are still discarded by the client
	// if IdleTimeout is set.
	IdleCheckFrequency string `yaml:"idle-check-frequency"`
}

RedisCommonConfig redis common config for simple,sentinel,cluster

type RedisConfig

type RedisConfig struct {
	RedisSimpleConfig `yaml:",inline"`
	RedisCommonConfig `yaml:",inline"`
	Mode              string              `yaml:"mode"` // 3种模式 1 simple (单机/主从) 2 sentinel 哨兵模式 3 cluster 集群模式
	Sentinel          RedisSentinelConfig `yaml:"sentinel"`
	Cluster           RedisClusterConfig  `yaml:"cluster"`
}

RedisConfig redis配置

func Redis

func Redis() RedisConfig

Redis return redis config

type RedisSentinelConfig

type RedisSentinelConfig struct {
	Master   string   `yaml:"master"`     // The master name.
	Addrs    []string `yaml:"addrs,flow"` // A seed list of host:port addresses of sentinel nodes.
	Username string   `yaml:"username"`
	Password string   `yaml:"password"`
}

RedisSentinelConfig redis sentinel server config

type RedisSimpleConfig

type RedisSimpleConfig struct {
	// host:port address.
	Addr string
}

RedisSimpleConfig redis simple config for stand-alone or master/slave mode

type ServerConfig

type ServerConfig struct {
	Port int
}

ServerConfig server config

func Server

func Server() ServerConfig

Server server config

Jump to

Keyboard shortcuts

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