本文整理汇总了Golang中github.com/akutz/gofig/types.Config类的典型用法代码示例。如果您正苦于以下问题:Golang Config类的具体用法?Golang Config怎么用?Golang Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: WriteTask
// WriteTask writes a task to a ResponseWriter.
func WriteTask(
ctx types.Context,
config gofig.Config,
w http.ResponseWriter,
store types.Store,
task *types.Task,
okStatus int) error {
if store.GetBool("async") {
WriteJSON(w, http.StatusAccepted, task)
return nil
}
exeTimeoutDur, err := time.ParseDuration(
config.GetString(types.ConfigServerTasksExeTimeout))
if err != nil {
exeTimeoutDur = time.Duration(time.Second * 60)
}
exeTimeout := time.NewTimer(exeTimeoutDur)
select {
case <-services.TaskWaitC(ctx, task.ID):
if task.Error != nil {
return task.Error
}
WriteJSON(w, okStatus, task.Result)
case <-exeTimeout.C:
WriteJSON(w, http.StatusRequestTimeout, task)
}
return nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:33,代码来源:httputils.go
示例2: UpdateLogLevel
// UpdateLogLevel updates the log level based on the config.
func UpdateLogLevel(config gofig.Config) {
ll, err := log.ParseLevel(config.GetString(types.ConfigLogLevel))
if err != nil {
return
}
log.SetLevel(ll)
}
开发者ID:emccode,项目名称:libstorage,代码行数:8,代码来源:config.go
示例3: startTimeout
func startTimeout(config gofig.Config) time.Duration {
dur, err := time.ParseDuration(
config.GetString("rexray.module.startTimeout"))
if err != nil {
return time.Duration(10) * time.Second
}
return dur
}
开发者ID:akutz,项目名称:rexray,代码行数:8,代码来源:module.go
示例4: printKeys
func printKeys(title string, c types.Config, t *testing.T) {
for _, k := range c.AllKeys() {
if title == "" {
t.Logf(k)
} else {
t.Logf("%s - %s", title, k)
}
}
}
开发者ID:akutz,项目名称:gofig,代码行数:9,代码来源:gofig_test.go
示例5: setHost
func setHost(
ctx apitypes.Context,
config gofig.Config,
host string) apitypes.Context {
ctx = ctx.WithValue(context.HostKey, host)
ctx.WithField("host", host).Debug("set host in context")
config.Set(apitypes.ConfigHost, host)
ctx.WithField("host", host).Debug("set host in config")
return ctx
}
开发者ID:akutz,项目名称:rexray,代码行数:10,代码来源:util.go
示例6: Init
// Init initializes the service.
func (s *globalTaskService) Init(ctx types.Context, config gofig.Config) error {
s.tasks = map[int]*task{}
s.config = config
s.resultSchemaValidationEnabled = config.GetBool(
types.ConfigSchemaResponseValidationEnabled)
ctx.WithField("enabled", s.resultSchemaValidationEnabled).Debug(
"configured result schema validation")
return nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:12,代码来源:services_task.go
示例7: assertConfigEqualToJSONCompact
func assertConfigEqualToJSONCompact(
c1 types.Config,
j2 string,
t *testing.T) (types.Config, types.Config, bool) {
var err error
var j1 string
if j1, err = c1.ToJSONCompact(); err != nil {
t.Error(err)
return nil, nil, false
}
return assertJSONEqual(j1, j2, t)
}
开发者ID:akutz,项目名称:gofig,代码行数:12,代码来源:gofig_test.go
示例8: assertOsDrivers1
func assertOsDrivers1(t *testing.T, c types.Config) {
od := c.GetStringSlice("rexray.osDrivers")
if od == nil {
t.Fatalf("osDrivers == nil")
}
if len(od) != 1 {
t.Fatalf("len(osDrivers) != 1; == %d", len(od))
}
if od[0] != "linux" {
t.Fatalf("od[0] != linux; == %v", od[0])
}
}
开发者ID:akutz,项目名称:gofig,代码行数:12,代码来源:gofig_test.go
示例9: 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
}
开发者ID:emccode,项目名称:libstorage,代码行数:51,代码来源:tests.go
示例10: InitializeDefaultModules
// InitializeDefaultModules initializes the default modules.
func InitializeDefaultModules(
ctx apitypes.Context,
config gofig.Config) (<-chan error, error) {
modTypesRwl.RLock()
defer modTypesRwl.RUnlock()
var (
err error
mod *Instance
errs <-chan error
)
// enable path caching for the modules
config.Set(apitypes.ConfigIgVolOpsPathCacheEnabled, true)
ctx, config, errs, err = util.ActivateLibStorage(ctx, config)
if err != nil {
return nil, err
}
modConfigs, err := getConfiguredModules(ctx, config)
if err != nil {
return nil, err
}
ctx.WithField("len(modConfigs)", len(modConfigs)).Debug(
"got configured modules")
for _, mc := range modConfigs {
ctx.WithField("name", mc.Name).Debug(
"creating libStorage client for module instance")
if mc.Client, err = util.NewClient(ctx, mc.Config); err != nil {
panic(err)
}
if mod, err = InitializeModule(ctx, mc); err != nil {
return nil, err
}
modInstances[mod.Name] = mod
}
return errs, nil
}
开发者ID:akutz,项目名称:rexray,代码行数:48,代码来源:module.go
示例11: activateLibStorage
func activateLibStorage(
ctx apitypes.Context,
config gofig.Config) (apitypes.Context, gofig.Config, <-chan error, error) {
var (
host string
isRunning bool
)
if host = config.GetString(apitypes.ConfigHost); host == "" {
if host, isRunning = IsLocalServerActive(ctx, config); isRunning {
ctx = setHost(ctx, config, host)
}
}
if host == "" && !isRunning {
return ctx, config, nil, errors.New("libStorage host config missing")
}
return ctx, config, nil, nil
}
开发者ID:akutz,项目名称:rexray,代码行数:17,代码来源:util_client_agent.go
示例12: assertStorageDrivers
func assertStorageDrivers(t *testing.T, c types.Config) {
sd := c.GetStringSlice("rexray.storageDrivers")
if sd == nil {
t.Fatalf("storageDrivers == nil")
}
if len(sd) != 2 {
t.Fatalf("len(storageDrivers) != 2; == %d", len(sd))
}
if sd[0] != "ec2" {
t.Fatalf("sd[0] != ec2; == %v", sd[0])
}
if sd[1] != "xtremio" {
t.Fatalf("sd[1] != xtremio; == %v", sd[1])
}
}
开发者ID:akutz,项目名称:gofig,代码行数:18,代码来源:gofig_test.go
示例13: isSet
func isSet(
config gofig.Config,
key string,
roots ...string) bool {
for _, r := range roots {
rk := strings.Replace(key, "libstorage.", fmt.Sprintf("%s.", r), 1)
if config.IsSet(rk) {
return true
}
}
if config.IsSet(key) {
return true
}
return false
}
开发者ID:emccode,项目名称:libstorage,代码行数:18,代码来源:utils_config.go
示例14: getConfiguredModules
func getConfiguredModules(
ctx apitypes.Context, c gofig.Config) ([]*Config, error) {
mods := c.Get("rexray.modules")
modMap, ok := mods.(map[string]interface{})
if !ok {
return nil, goof.New("invalid format rexray.modules")
}
ctx.WithField("count", len(modMap)).Debug("got modules map")
modConfigs := []*Config{}
for name := range modMap {
name = strings.ToLower(name)
ctx.WithField("name", name).Debug("processing module config")
sc := c.Scope(fmt.Sprintf("rexray.modules.%s", name))
if disabled := sc.GetBool("disabled"); disabled {
ctx.WithField("name", name).Debug("ignoring disabled module config")
continue
}
mc := &Config{
Name: name,
Type: strings.ToLower(sc.GetString("type")),
Description: sc.GetString("desc"),
Address: sc.GetString("host"),
Config: sc,
}
ctx.WithFields(log.Fields{
"name": mc.Name,
"type": mc.Type,
"desc": mc.Description,
"addr": mc.Address,
}).Info("created new mod config")
modConfigs = append(modConfigs, mc)
}
return modConfigs, nil
}
开发者ID:akutz,项目名称:rexray,代码行数:43,代码来源:module.go
示例15: Scope
func (c *scopedConfig) Scope(scope interface{}) types.Config {
szScope := toString(scope)
if log.GetLevel() == log.DebugLevel {
scopes := []string{}
var p types.Config = c
for {
scopes = append(scopes, p.GetScope())
p = p.Parent()
if p == nil {
break
}
}
log.WithFields(log.Fields{
"new": szScope,
"parentScopes": strings.Join(scopes, ","),
}).Debug("created scoped scope")
}
return &scopedConfig{Config: c, scope: szScope}
}
开发者ID:akutz,项目名称:gofig,代码行数:19,代码来源:gofig.go
示例16: getString
func getString(
config gofig.Config,
key string,
roots ...string) string {
var val string
for _, r := range roots {
rk := strings.Replace(key, "libstorage.", fmt.Sprintf("%s.", r), 1)
if val = config.GetString(rk); val != "" {
return val
}
}
val = config.GetString(key)
if val != "" {
return val
}
return ""
}
开发者ID:emccode,项目名称:libstorage,代码行数:21,代码来源:utils_config.go
示例17: 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
}
开发者ID:akutz,项目名称:rexray,代码行数:32,代码来源:util_libstorage.go
示例18: BackCompat
// BackCompat ensures keys can be used from old configurations.
func BackCompat(config gofig.Config) {
checks := [][]string{
{ConfigIgVolOpsMountPreempt, ConfigOldIntegrationVolMountPreempt},
{ConfigIgVolOpsCreateDisable, ConfigOldIntegrationVolCreateDisable},
{ConfigIgVolOpsRemoveDisable, ConfigOldIntegrationVolRemoveDisable},
{ConfigIgVolOpsUnmountIgnoreUsed, ConfigOldIntegrationVolUnmountIgnoreUsed},
{ConfigIgVolOpsPathCacheEnabled, ConfigOldIntegrationVolPathCache},
{ConfigIgVolOpsCreateDefaultFsType, ConfigOldDockerFsType},
{ConfigIgVolOpsCreateDefaultType, ConfigOldDockerVolumeType},
{ConfigIgVolOpsCreateDefaultIOPS, ConfigOldDockerIOPS},
{ConfigIgVolOpsCreateDefaultSize, ConfigOldDockerSize},
{ConfigIgVolOpsCreateDefaultAZ, ConfigOldDockerAvailabilityZone},
{ConfigIgVolOpsMountPath, ConfigOldDockerMountDirPath},
{ConfigIgVolOpsMountRootPath, ConfigOldDockerLinuxVolumeRootPath},
}
for _, check := range checks {
if !config.IsSet(check[0]) && config.IsSet(check[1]) {
log.Debug(config.Get(check[1]))
config.Set(check[0], config.Get(check[1]))
}
}
}
开发者ID:emccode,项目名称:libstorage,代码行数:23,代码来源:types_config_compat.go
示例19: printConfig
func printConfig(title string, c types.Config, t *testing.T) {
for _, k := range c.AllKeys() {
if title == "" {
t.Logf("%s=%v", k, c.Get(k))
} else {
t.Logf("%s - %s=%v", title, k, c.Get(k))
}
}
}
开发者ID:akutz,项目名称:gofig,代码行数:9,代码来源:gofig_test.go
示例20: assertConfigsEqual
func assertConfigsEqual(c1 types.Config, c2 types.Config, t *testing.T) bool {
printConfig("c1", c1, t)
t.Log("")
printConfig("c2", c2, t)
t.Log("")
c1Keys := c1.AllKeys()
c2Keys := c2.AllKeys()
for _, k := range c1Keys {
c1v := c1.Get(k)
c2v := c2.Get(k)
if !reflect.DeepEqual(c1v, c2v) {
t.Logf("%s != in both configs; "+
"c1v:type=%[2]T,val=%[2]v; "+
"c2v:type=%[3]T,val=%[3]v", k, c1v, c2v)
return false
}
}
for _, k := range c2Keys {
c1v := c1.Get(k)
c2v := c2.Get(k)
if !reflect.DeepEqual(c1v, c2v) {
t.Logf("%s != in both configs; "+
"c1v:type=%[2]T,val=%[2]v; "+
"c2v:type=%[3]T,val=%[3]v", k, c1v, c2v)
return false
}
}
return true
}
开发者ID:akutz,项目名称:gofig,代码行数:34,代码来源:gofig_test.go
注:本文中的github.com/akutz/gofig/types.Config类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论