当前位置: 首页>>代码示例>>Golang>>正文


Golang Config.Scope方法代码示例

本文整理汇总了Golang中github.com/akutz/gofig/types.Config.Scope方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.Scope方法的具体用法?Golang Config.Scope怎么用?Golang Config.Scope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/akutz/gofig/types.Config的用法示例。


在下文中一共展示了Config.Scope方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ActivateLibStorage

// ActivateLibStorage activates libStorage and returns a possibly mutated
// context.
func ActivateLibStorage(
	ctx apitypes.Context,
	config gofig.Config) (apitypes.Context, gofig.Config, <-chan error, error) {

	config = config.Scope("rexray")

	// set the `libstorage.service` property to the value of
	// `rexray.storageDrivers` if the former is not defined and the
	// latter is
	if !config.IsSet(apitypes.ConfigService) &&
		config.IsSet("rexray.storageDrivers") {
		if sd := config.GetStringSlice("rexray.storageDrivers"); len(sd) > 0 {
			config.Set(apitypes.ConfigService, sd[0])
		} else if sd := config.GetString("rexray.storageDrivers"); sd != "" {
			config.Set(apitypes.ConfigService, sd)
		}
	}

	if !config.IsSet(apitypes.ConfigIgVolOpsMountPath) {
		config.Set(apitypes.ConfigIgVolOpsMountPath, LibFilePath("volumes"))
	}

	var (
		err  error
		errs <-chan error
	)

	ctx, config, errs, err = activateLibStorage(ctx, config)
	if err != nil {
		return ctx, config, errs, err
	}

	return ctx, config, errs, nil
}
开发者ID:akutz,项目名称:rexray,代码行数:36,代码来源:util.go

示例2: 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

示例3: 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

示例4: newServer

func newServer(goCtx gocontext.Context, config gofig.Config) (*server, error) {

	adminTokenUUID, err := types.NewUUID()
	if err != nil {
		return nil, err
	}
	adminToken := adminTokenUUID.String()
	serverName := randomServerName()

	ctx := context.New(goCtx)
	ctx = ctx.WithValue(context.ServerKey, serverName)
	ctx = ctx.WithValue(context.AdminTokenKey, adminToken)

	if lvl, ok := context.GetLogLevel(ctx); ok {
		switch lvl {
		case log.DebugLevel:
			ctx = context.WithValue(
				ctx, gournal.LevelKey(),
				gournal.DebugLevel)
		case log.InfoLevel:
			ctx = context.WithValue(
				ctx, gournal.LevelKey(),
				gournal.InfoLevel)
		case log.WarnLevel:
			ctx = context.WithValue(
				ctx, gournal.LevelKey(),
				gournal.WarnLevel)
		case log.ErrorLevel:
			ctx = context.WithValue(
				ctx, gournal.LevelKey(),
				gournal.ErrorLevel)
		case log.FatalLevel:
			ctx = context.WithValue(
				ctx, gournal.LevelKey(),
				gournal.FatalLevel)
		case log.PanicLevel:
			ctx = context.WithValue(
				ctx, gournal.LevelKey(),
				gournal.PanicLevel)
		}
	}

	if logger, ok := ctx.Value(context.LoggerKey).(*log.Logger); ok {
		ctx = context.WithValue(
			ctx, gournal.AppenderKey(),
			glogrus.NewWithOptions(
				logger.Out, logger.Level, logger.Formatter))
	}

	if config == nil {
		var err error
		if config, err = apicnfg.NewConfig(); err != nil {
			return nil, err
		}
	}
	config = config.Scope(types.ConfigServer)

	s := &server{
		ctx:          ctx,
		name:         serverName,
		adminToken:   adminToken,
		config:       config,
		closeSignal:  make(chan int),
		closedSignal: make(chan int),
		closeOnce:    &sync.Once{},
	}

	if logger, ok := s.ctx.Value(context.LoggerKey).(*log.Logger); ok {
		s.PrintServerStartupHeader(logger.Out)
	} else {
		s.PrintServerStartupHeader(os.Stdout)
	}

	if lvl, err := log.ParseLevel(
		config.GetString(types.ConfigLogLevel)); err == nil {
		context.SetLogLevel(s.ctx, lvl)
	}

	logFields := log.Fields{}
	logConfig, err := utils.ParseLoggingConfig(
		config, logFields, "libstorage.server")
	if err != nil {
		return nil, err
	}

	// always update the server context's log level
	context.SetLogLevel(s.ctx, logConfig.Level)
	s.ctx.WithFields(logFields).Info("configured logging")

	s.ctx.Info("initializing server")

	if err := s.initEndpoints(s.ctx); err != nil {
		return nil, err
	}
	s.ctx.Info("initialized endpoints")

	if err := services.Init(s.ctx, s.config); err != nil {
		return nil, err
	}
	s.ctx.Info("initialized services")
//.........这里部分代码省略.........
开发者ID:emccode,项目名称:libstorage,代码行数:101,代码来源:server.go

示例5: New

// New returns a new libStorage client.
func New(goCtx gocontext.Context, config gofig.Config) (types.Client, error) {

	if config == nil {
		var err error
		if config, err = apicnfg.NewConfig(); err != nil {
			return nil, err
		}
	}

	config = config.Scope(types.ConfigClient)
	types.BackCompat(config)

	var (
		c   *client
		err error
	)

	c = &client{ctx: context.New(goCtx), config: config}
	c.ctx = c.ctx.WithValue(context.ClientKey, c)

	logFields := log.Fields{}
	logConfig, err := utils.ParseLoggingConfig(
		config, logFields, "libstorage.client")
	if err != nil {
		return nil, err
	}

	// always update the server context's log level
	context.SetLogLevel(c.ctx, logConfig.Level)
	c.ctx.WithFields(logFields).Info("configured logging")

	if config.IsSet(types.ConfigService) {
		c.ctx = c.ctx.WithValue(
			context.ServiceKey, config.GetString(types.ConfigService))
	}

	storDriverName := config.GetString(types.ConfigStorageDriver)
	if storDriverName == "" {
		c.ctx.Warn("no storage driver found")
	} else {
		if c.sd, err = registry.NewStorageDriver(storDriverName); err != nil {
			return nil, err
		}
		if err = c.sd.Init(c.ctx, config); err != nil {
			return nil, err
		}
		if papi, ok := c.sd.(types.ProvidesAPIClient); ok {
			c.api = papi.API()
		}
		if pxli, pxliOk := c.sd.(types.ProvidesStorageExecutorCLI); pxliOk {
			c.xli = pxli.XCLI()
		}
		c.ctx.Info("storage driver initialized")
	}

	// if the API or XLI are nil, then the storage driver is not the libStorage
	// storage driver, and we should jump avoid any more initialization
	if c.api == nil || c.xli == nil {
		c.ctx.Info("created libStorage client")
		return c, nil
	}

	osDriverName := config.GetString(types.ConfigOSDriver)
	if osDriverName == "" {
		c.ctx.Warn("no os driver found")
	} else {
		if c.od, err = registry.NewOSDriver(osDriverName); err != nil {
			return nil, err
		}
		if err = c.od.Init(c.ctx, config); err != nil {
			return nil, err
		}
		c.ctx.Info("os driver initialized")
	}

	intDriverName := config.GetString(types.ConfigIntegrationDriver)
	if intDriverName == "" {
		c.ctx.Warn("no integration driver found")
	} else {
		if c.id, err = registry.NewIntegrationDriver(
			intDriverName); err != nil {
			return nil, err
		}
		if err := c.id.Init(c.ctx, config); err != nil {
			return nil, err
		}
		c.ctx.Info("integration driver initialized")
	}

	c.ctx.Info("created libStorage client")
	return c, nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:93,代码来源:client.go


注:本文中的github.com/akutz/gofig/types.Config.Scope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。