config

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

README

配置组件

  • 可支持本地的.env配置文件
  • 可支持共享配置

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(conf interface{}) error

func InitRemote added in v0.1.1

func InitRemote(provider, endpoint, configPath string, conf interface{}) error

func Read

func Read(section string, cfg interface{}) error

Types

type CORSConfig

type CORSConfig struct {
	Origins []string `mapstructure:"origins"`
	Methods []string `mapstructure:"methods"`
	Headers []string `mapstructure:"headers"`
}

func (*CORSConfig) Allows

func (cfg *CORSConfig) Allows(h http.Handler) http.Handler

type CertConfig

type CertConfig struct {
	PublicKey  string `mapstructure:"pub"` // PublicKey 返回公钥文件地址
	PrivateKey string `mapstructure:"key"` // PrivateKey 返回私钥文件地址
}

type Config

type Config struct {
	DB      DBConfig      `mapstructure:"db"`      // DB 数据库连接配置
	Service ServerConfig  `mapstructure:"service"` // Service 服务配置
	Gateway GatewayConfig `mapstructure:"gateway"`
	Cert    CertConfig    `mapstructure:"sign"` // Cert JWT 使用RSA的密钥配置
}

type DBConfig

type DBConfig struct {
	Name     string `mapstructure:"name"`
	Database string `mapstructure:"database"`
	Host     string `mapstructure:"addr"`
	Port     int    `mapstructure:"port"`
	User     string `mapstructure:"user"`
	Password string `mapstructure:"password"`
}

func (*DBConfig) DSN

func (conf *DBConfig) DSN() string

type EndPoint

type EndPoint struct {
	Name     string `mapstructure:"name"`
	Addr     string `mapstructure:"addr"`
	TTL      int    `mapstructure:"ttl"`
	Network  string `mapstructure:"network"`
	TLS      bool   `mapstructure:"tls"`  // 是否使用证TLS证书
	KeyFile  string `mapstructure:"key"`  // 私钥文件
	CertFile string `mapstructure:"cert"` // 公钥文件
	CAFile   string `mapstructure:"ca"`   // Ca文件
}

func DefaultEndPoint

func DefaultEndPoint() *EndPoint

func NewEndpoint

func NewEndpoint(addr string) *EndPoint

func (*EndPoint) GetHost

func (cfg *EndPoint) GetHost() string

func (*EndPoint) GetPort

func (cfg *EndPoint) GetPort() int

func (*EndPoint) LocalIP

func (cfg *EndPoint) LocalIP() string

获取本机ip地址

func (*EndPoint) LocalListener

func (cfg *EndPoint) LocalListener(listener net.Listener, host string, err error)

自动获取本机的ip以及端口号,ip:port格式

func (*EndPoint) SetDefault

func (cfg *EndPoint) SetDefault()

type GatewayConfig

type GatewayConfig struct {
	Name          string      `mapstructure:"name"`
	EndPoint      *EndPoint   `mapstructure:"endpoint"`
	Transports    []*EndPoint `mapstructure:"trans"`
	RegistryAddrs []string    `mapstructure:"registry"`
	CORS          *CORSConfig `mapstructure:"cors"`
}

type ServerConfig

type ServerConfig struct {
	Name          string    `mapstructure:"name"`
	EndPoint      *EndPoint `mapstructure:"endpoint"`
	RegistryAddrs []string  `mapstructure:"registry"`
}

Jump to

Keyboard shortcuts

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