本文整理汇总了Golang中github.com/akutz/gofig/types.Config.ReadConfig方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.ReadConfig方法的具体用法?Golang Config.ReadConfig怎么用?Golang Config.ReadConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/akutz/gofig/types.Config
的用法示例。
在下文中一共展示了Config.ReadConfig方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: initDefaultLibStorageServices
// initDefaultLibStorageServices initializes the config object with a default
// libStorage service if one is not present.
//
// TODO Move this into libStorage in libStorage 0.1.2
func initDefaultLibStorageServices(
ctx apitypes.Context, config gofig.Config) error {
if config.IsSet(apitypes.ConfigServices) {
ctx.Debug(
"libStorage auto service mode disabled; services defined")
return nil
}
serviceName := config.GetString(apitypes.ConfigService)
if serviceName == "" {
ctx.Debug(
"libStorage auto service mode disabled; service name empty")
return nil
}
ctx.WithField("driver", serviceName).Info(
"libStorage auto service mode enabled")
buf := &bytes.Buffer{}
fmt.Fprintf(buf, defaultServiceConfigFormat, serviceName)
if err := config.ReadConfig(buf); err != nil {
return err
}
return nil
}
示例2: getTestConfigs
func getTestConfigs(
t *testing.T,
driver string,
config gofig.Config) (map[int]string, []gofig.Config) {
libstorageConfigMap := map[string]interface{}{
"server": map[string]interface{}{
"services": map[string]interface{}{
driver: map[string]interface{}{
"libstorage": map[string]interface{}{
"storage": map[string]interface{}{
"driver": driver,
},
},
},
},
},
}
initTestConfigs(libstorageConfigMap)
libstorageConfig := map[string]interface{}{
"libstorage": libstorageConfigMap,
}
yamlBuf, err := yaml.Marshal(libstorageConfig)
assert.NoError(t, err)
assert.NoError(t, config.ReadConfig(bytes.NewReader(yamlBuf)))
configNames := map[int]string{}
configs := []gofig.Config{}
if tcpTest {
configNames[len(configNames)] = "tcp"
configs = append(configs, config.Scope("libstorage.tests.tcp"))
}
if tcpTLSTest {
configNames[len(configNames)] = "tcpTLS"
configs = append(configs, config.Scope("libstorage.tests.tcpTLS"))
}
if sockTest {
configNames[len(configNames)] = "unix"
configs = append(configs, config.Scope("libstorage.tests.unix"))
}
if sockTLSTest {
configNames[len(configNames)] = "unixTLS"
configs = append(configs, config.Scope("libstorage.tests.unixTLS"))
}
return configNames, configs
}