• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang envconf.Environment类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/kitcambridge/envconf.Environment的典型用法代码示例。如果您正苦于以下问题:Golang Environment类的具体用法?Golang Environment怎么用?Golang Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: LoadExtensibleSection

// Load an extensible section that has a type keyword
func LoadExtensibleSection(app *Application, sectionName string,
	extensions AvailableExtensions, env envconf.Environment,
	configFile ConfigFile) (obj HasConfigStruct, err error) {

	confSection := new(ExtensibleGlobals)

	conf, ok := configFile[sectionName]
	if !ok {
		return nil, fmt.Errorf("Missing section '%s'", sectionName)
	}

	if err = toml.PrimitiveDecode(conf, confSection); err != nil {
		return nil, err
	}
	if err = env.Decode(toEnvName(sectionName), EnvSep, confSection); err != nil {
		return nil, err
	}
	ext, ok := extensions.Get(confSection.Typ)
	if !ok {
		//TODO: Add log info to indicate using "default"
		return nil, fmt.Errorf("No type '%s' available to load for section '%s'",
			confSection.Typ, sectionName)
	}

	obj = ext()
	loadedConfig, err := LoadConfigStruct(sectionName, env, conf, obj)
	if err != nil {
		return nil, err
	}

	err = obj.Init(app, loadedConfig)
	return obj, err
}
开发者ID:jrconlin,项目名称:pushgo,代码行数:34,代码来源:config.go


示例2: LoadConfigForSection

// Loads the config for a section supplied, configures the supplied object, and initializes
func LoadConfigForSection(app *Application, sectionName string, obj HasConfigStruct,
	env envconf.Environment, configFile ConfigFile) (err error) {

	conf, ok := configFile[sectionName]
	if !ok {
		return fmt.Errorf("Error loading config file, section: %s", sectionName)
	}
	confStruct := obj.ConfigStruct()
	if confStruct == nil {
		return nil
	}

	if err = toml.PrimitiveDecode(conf, confStruct); err != nil {
		return fmt.Errorf("Unable to decode config for section '%s': %s",
			sectionName, err)
	}

	if err = env.Decode(toEnvName(sectionName), EnvSep, confStruct); err != nil {
		return fmt.Errorf("Invalid environment variable for section '%s': %s",
			sectionName, err)
	}

	err = obj.Init(app, confStruct)
	return
}
开发者ID:shihuacai1989,项目名称:pushgo,代码行数:26,代码来源:config.go


示例3: loadEnvConfig

func loadEnvConfig(env envconf.Environment, section string,
	app *Application, configable HasConfigStruct) (err error) {

	confStruct := configable.ConfigStruct()
	if err = env.Decode(toEnvName(section), EnvSep, confStruct); err != nil {
		return fmt.Errorf("Error decoding config for section %q: %s",
			section, err)
	}
	return configable.Init(app, confStruct)
}
开发者ID:shihuacai1989,项目名称:pushgo,代码行数:10,代码来源:config_test.go


示例4: LoadConfigFromEnvironment

// Applies environment variable overrides to confStruct and initializes obj
func LoadConfigFromEnvironment(app *Application, sectionName string,
	obj HasInit, env envconf.Environment, confStruct interface{}) (err error) {

	if confStruct == nil {
		return nil
	}
	if err = env.Decode(toEnvName(sectionName), EnvSep, confStruct); err != nil {
		return fmt.Errorf("Invalid environment variable for section '%s': %s",
			sectionName, err)
	}
	return obj.Init(app, confStruct)
}
开发者ID:jrconlin,项目名称:pushgo,代码行数:13,代码来源:config.go


示例5: LoadConfigStruct

func LoadConfigStruct(sectionName string, env envconf.Environment,
	config toml.Primitive, configable HasConfigStruct) (
	configStruct interface{}, err error) {

	if configStruct = configable.ConfigStruct(); configStruct == nil {
		return configStruct, nil
	}

	// Global section options
	// SimplePush defines some common parameters
	// that are defined in the ExtensibleGlobals struct.
	// Use reflection to extract the tagged ExtensibleGlobals fields.
	var pg ExtensibleGlobals
	rt := reflect.TypeOf(pg)

	ignoreConfig := make(map[string]interface{}, rt.NumField())
	ignoreEnv := make(map[string]interface{}, rt.NumField())

	for i := 0; i < rt.NumField(); i++ {
		sft := rt.Field(i)
		kname := sft.Tag.Get("toml")
		if len(kname) == 0 {
			kname = sft.Name
		}
		ignoreConfig[kname] = true
		if kname = sft.Tag.Get("env"); len(kname) == 0 {
			kname = sft.Name
		}
		ignoreEnv[toEnvName(sectionName, kname)] = true
	}

	if err = toml.PrimitiveDecodeStrict(config, configStruct, ignoreConfig); err != nil {
		matches := unknownOptionRegex.FindStringSubmatch(err.Error())
		if len(matches) == 2 {
			// We've got an unrecognized config option.
			err = fmt.Errorf("Unknown config setting for section '%s': %s",
				sectionName, matches[1])
		}
		return nil, err
	}

	if err = env.DecodeStrict(toEnvName(sectionName), EnvSep, configStruct, ignoreEnv); err != nil {
		return nil, fmt.Errorf("Invalid environment variable for section '%s': %s",
			sectionName, err)
	}

	return configStruct, nil
}
开发者ID:jrconlin,项目名称:pushgo,代码行数:48,代码来源:config.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang vips.Image类代码示例发布时间:2022-05-23
下一篇:
Golang log4go.Info函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap