Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config raw config
func (*Config) MustScanConfig ¶
func (x *Config) MustScanConfig(i interface{})
MustScanConfig 求出强类型配置
func (*Config) MustToYaml ¶
func (*Config) ScanConfig ¶
ScanConfig 求出强类型配置 todo 用 github.com/ghodss/yaml 来避免json/yaml转换问题
Example ¶
package main import ( "fmt" "github.com/chen56/go-common/configs" "github.com/chen56/go-common/must" ) type Log struct { Level string `yaml:"level" json:"level"` } type Conf struct { Log Log `yaml:"log" json:"log"` AppInfo string `yaml:"appInfo" json:"appInfo"` } func main() { var config1 = configs.NewMemoryConfigSource([]byte(` log: level: error appInfo: log=${log_level} `)) var config2 = configs.NewMemoryConfigSource([]byte(` log: level: debug `)) c := configs.NewConfig(configs.NewConfigOptions{ConfigSources: []configs.ConfigSource{config1, config2}}) conf := Conf{} err := c.ScanConfig(&conf) must.NoError(err) //spew.Dump(c) fmt.Printf("%+v", conf) }
Output: {Log:{Level:debug} AppInfo:log=debug}
type ConfigSource ¶
ConfigSource 配置源,配置可以从字符串/文件/网络读取
func NewFileConfigSource ¶
func NewFileConfigSource(path string) ConfigSource
NewFileConfigSource 文件配置源
func NewInterfaceConfigSource ¶
func NewInterfaceConfigSource(conf interface{}) ConfigSource
NewMemoryConfigSource 内存配置源
func NewMemoryConfigSource ¶
func NewMemoryConfigSource(data []byte) ConfigSource
NewMemoryConfigSource 内存配置源
type NewConfigOptions ¶
type NewConfigOptions struct {
ConfigSources []ConfigSource
}
NewConfigOptions 选项
Directories ¶
Path | Synopsis |
---|---|
grpc_auth copy from https://github.com/grpc-ecosystem/go-grpc-middleware/tree/master/auth 因为原auth的AuthFunc没有提供fullMethodName参数: type AuthFunc func(ctx context.Context) (context.Context, error) 所以复制来改为: type AuthFunc func(ctx context.Context, fullMethodName string) (context.Context, error) 没有其他修改,使用流程和原auth一致
|
grpc_auth copy from https://github.com/grpc-ecosystem/go-grpc-middleware/tree/master/auth 因为原auth的AuthFunc没有提供fullMethodName参数: type AuthFunc func(ctx context.Context) (context.Context, error) 所以复制来改为: type AuthFunc func(ctx context.Context, fullMethodName string) (context.Context, error) 没有其他修改,使用流程和原auth一致 |
Click to show internal directories.
Click to hide internal directories.