// Adapter is the interface for configuration retrieving.
type Adapter interface {
// Available checks and returns the configuration service is available.
// The optional parameter `resource` specifies certain configuration resource.
//
// It returns true if configuration file is present in default AdapterFile, or else false.
// Note that this function does not return error as it just does simply check for backend configuration service.
Available(ctx context.Context, resource ...string) (ok bool)
// Get retrieves and returns value by specified `pattern`.
Get(ctx context.Context, pattern string) (value interface{}, err error)
// Data retrieves and returns all configuration data as map type.
// Note that this function may lead lots of memory usage if configuration data is too large,
// you can implement this function if necessary.
Data(ctx context.Context) (data map[string]interface{}, err error)
}
4 Comments
pppp
1.x版本是不是无法实现使用etcd或k8s configmap?
朱华 Hunk
这个是不是只有2.x版本可以用哦?没发现g.Cfg()有SetAdapter方法呢。。
lfzxs
有没例子,想从nacos获取配置
糖水不加糖
adapter, err := nacos.New(ctx, nacos.Config{
ServerConfigs: []constant.ServerConfig{serverConfig},
ClientConfig: clientConfig,
ConfigParam: configParam,
Watch: true,
})
if err != nil {
g.Log().Fatalf(ctx, `%+v`, err)
}
// Change the adapter of default configuration instance.
g.Cfg().SetAdapter(adapter)