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

Golang viper.ConfigFileUsed函数代码示例

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

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



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

示例1: initConfig

// initConfig reads in config file and ENV variables if set.
func initConfig() {
	if cfgFile != "" { // enable ability to specify config file via flag
		viper.SetConfigFile(cfgFile)
	}

	viper.SetConfigName("." + NAME) // name of config file (without extension)
	viper.AddConfigPath("$HOME")    // adding home directory as first search path
	viper.AutomaticEnv()            // read in environment variables that match
	viper.ConfigFileUsed()

	// If a config file is found, read it in.
	if err := viper.ReadInConfig(); err == nil {
		fmt.Println("Using config file:", viper.ConfigFileUsed())
	}
}
开发者ID:clns,项目名称:izip-client,代码行数:16,代码来源:root.go


示例2: Persist

func (c *Config) Persist() error {
	_ = c.GetIssuer()
	_ = c.GetAddress()
	_ = c.GetClusterURL()

	out, err := yaml.Marshal(c)
	if err != nil {
		return errors.New(err)
	}

	if err := ioutil.WriteFile(viper.ConfigFileUsed(), out, 0700); err != nil {
		return errors.Errorf(`Could not write to "%s" because: %s`, viper.ConfigFileUsed(), err)
	}
	return nil
}
开发者ID:jemacom,项目名称:hydra,代码行数:15,代码来源:config.go


示例3: PrintConfig

func PrintConfig(ctx log.Interface, debug bool) {
	prt := ctx.Infof
	if debug {
		prt = ctx.Debugf
	}

	prt("Using config:")
	fmt.Println()
	printKV("config file", viper.ConfigFileUsed())
	printKV("data dir", viper.GetString("data"))
	fmt.Println()

	for key, val := range viper.AllSettings() {
		switch key {
		case "builddate":
			fallthrough
		case "gitcommit":
			fallthrough
		case "gitbranch":
			fallthrough
		case "version":
			continue
		default:
			printKV(key, val)
		}
	}
	fmt.Println()
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:28,代码来源:print_config.go


示例4: SaveViperConfig

func SaveViperConfig() error {
	cfg := viper.ConfigFileUsed()
	if cfg == "" {
		usr, err := user.Current()
		if err != nil {
			return err
		}
		cfg = filepath.Join(usr.HomeDir, "."+NAME+".yaml")
	}
	f, err := os.Create(cfg)
	if err != nil {
		return err
	}
	defer f.Close()

	all := viper.AllSettings()
	b, err := yaml.Marshal(all)
	if err != nil {
		return fmt.Errorf("Panic while encoding into YAML format.")
	}
	if _, err := f.WriteString(string(b)); err != nil {
		return err
	}
	return nil
}
开发者ID:clns,项目名称:izip-client,代码行数:25,代码来源:viper.go


示例5: initConfig

// initConfig reads in config file and ENV variables if set.
func initConfig() {
	if len(cfgFile) != 0 {
		viper.SetConfigFile(cfgFile)
	}

	viper.SetConfigName(".otp-config")
	viper.AddConfigPath("$HOME")
	viper.AutomaticEnv()

	apiKey, _ := RootCmd.Flags().GetString("api-key")
	if len(apiKey) == 0 && len(os.Getenv("GITHUB_API_KEY")) > 0 {
		RootCmd.Flags().Set("api-key", os.Getenv("GITHUB_API_KEY"))
	}
	if len(apiKey) > 0 {
		if err := os.Setenv("GITHUB_API_KEY", apiKey); err != nil {
			fmt.Fprintf(os.Stderr, "Error: Unable to set GITHUB_API_KEY\n")
			os.Exit(1)
		}
	}

	// If a config file is found, read it in.
	if err := viper.ReadInConfig(); err == nil {
		fmt.Println("Using config file:", viper.ConfigFileUsed())
	}

	log.SetFormatter(&log.TextFormatter{})
	log.SetOutput(os.Stderr)
	if api.Verbose {
		log.SetLevel(log.DebugLevel)
	} else {
		log.SetLevel(log.WarnLevel)
	}
}
开发者ID:mfojtik,项目名称:dev-tools,代码行数:34,代码来源:root.go


示例6: initConfig

// initConfig reads in config file and ENV variables if set.
func initConfig() {
	if cfgFile != "" { // enable ability to specify config file via flag
		viper.SetConfigFile(cfgFile)
	}

	viper.SetConfigName(".ata")  // name of config file (without extension)
	viper.AddConfigPath("$HOME") // adding home directory as first search path
	viper.AutomaticEnv()         // read in environment variables that match

	// If a config file is found, read it in.
	if err := viper.ReadInConfig(); err == nil {
		fmt.Println("Using config file:", viper.ConfigFileUsed())
	}

	// deal with verbose and debug mode
	if DebugMode {
		logger.SetLevel(logging.DebugLevel)
	}
	logger.ActivateVerboseOutput(VerboseMode)

	// check that work directory exists
	if !io.DirectoryExists(WorkDirectory) {
		log.Fatalf("Work directory '%s' does not exist or is not readable", WorkDirectory)
	}
}
开发者ID:tahitianstud,项目名称:ata,代码行数:26,代码来源:root.go


示例7: initConfig

// initConfig reads in config file and ENV variables if set.
func initConfig(cmd *cobra.Command) {
	viper.SetConfigName(".skelly") // name of config file (without extension)
	viper.AddConfigPath("$HOME")   // adding home directory as first search path
	viper.SetConfigType("json")
	viper.AutomaticEnv() // read in environment variables that match

	fmt.Println("got here")
	// If a config file is found, read it in.
	if err := viper.ReadInConfig(); err == nil {
		fmt.Println("Using config file:", viper.ConfigFileUsed())
	}

	// Make sure that go src var is set
	gopath = viper.GetString("gopath")
	if len(gopath) <= 0 {
		gopath = joinPath(os.Getenv("GOPATH"), "src")
		viper.Set("gopath", gopath)
	}

	if cmd.Flags().Lookup("project-root").Changed {
		viper.Set("project-root", basePath)
	}
	if cmd.Flags().Lookup("author").Changed {
		fmt.Println("adding author")
		viper.Set("author", author)
	}
	if cmd.Flags().Lookup("email").Changed {
		viper.Set("email", email)
	}
	fmt.Println(email)
	if cmd.Flags().Lookup("license").Changed {
		viper.Set("license", license)
	}
}
开发者ID:lursu,项目名称:skelly,代码行数:35,代码来源:root.go


示例8: initConfig

// initConfig reads in config file and ENV variables if set.
func initConfig() {
	if config.ConfigFile != "" { // enable ability to specify config file via flag
		viper.SetConfigFile(config.ConfigFile)
	}

	viper.SetConfigName(subifyConfigFile) // name of config file (without extension)
	viper.AddConfigPath(subifyConfigPath) // adding home directory as first search path

	// If a config file is found, read it in.
	err := viper.ReadInConfig()
	if err == nil {
		fmt.Println("Using config file:" + viper.ConfigFileUsed())
	} else {
		fmt.Println("Cant read config file:" + viper.ConfigFileUsed())
	}
}
开发者ID:matcornic,项目名称:subify,代码行数:17,代码来源:root.go


示例9: Init

// Init calls flag.Parse() and, for now, sets up the
// credentials.
func (cs *CliState) Init() error {
	cs.flagSet.Parse(os.Args[1:])
	config.SetConfigName(".romana") // name of config file (without extension)
	config.SetConfigType("yaml")
	config.AddConfigPath("$HOME") // adding home directory as first search path
	config.AutomaticEnv()         // read in environment variables that match

	// If a config file is found, read it in.
	err := config.ReadInConfig()
	if err != nil {
		switch err := err.(type) {
		case config.ConfigFileNotFoundError:
			// For now do nothing
		case *os.PathError:
			if err.Error() != "open : no such file or directory" {
				return err
			}
		default:
			return err
		}
	}
	log.Infof("Using config file: %s", config.ConfigFileUsed())
	err = cs.credential.Initialize()
	return err
}
开发者ID:romana,项目名称:core,代码行数:27,代码来源:service.go


示例10: initConfig

// initConfig reads in config file and ENV variables if set.
func initConfig() {

	if cfgFile != "" { // enable ability to specify config file via flag
		viper.SetConfigFile(cfgFile)
	}

	viper.SetConfigName(".grnl") // name of config file (without extension)
	viper.AddConfigPath("$HOME") // adding home directory as first search path
	viper.AutomaticEnv()         // read in environment variables that match

	// If a config file is found, read it in.
	if err := viper.ReadInConfig(); err != nil {
		fmt.Printf("Error using config file %q\n%q", viper.ConfigFileUsed(), err)
	}

	if db != "" {
		viper.Set("db", db)
	}

	if editor != "" {
		viper.Set("editor", editor)
	}

	if dateFormat != "" {
		viper.Set("dateFormat", dateFormat)
	}
}
开发者ID:jzorn,项目名称:grnl,代码行数:28,代码来源:grnl.go


示例11: main

func main() {
	flag.Parse() // Scan the arguments list
	InitializeConfig()
	graphite := fmt.Sprintf("%s%s%s", viper.GetString("graphite.host"), ":", viper.GetString("graphite.port"))
	prefix := fmt.Sprintf("%s", viper.GetString("graphite.prefix"))

	if *versionFlag {
		fmt.Println("cnm2g: Cn=monitor to Graphite")
		fmt.Println("Version:", APP_VERSION)
		fmt.Println("Config File >>>", viper.ConfigFileUsed())
		fmt.Println("Graphite >>>", graphite)
		fmt.Println("Prefix >>>", prefix)
		return
	}
	ldapmap := viper.GetStringMap("ldap")
	dnmap := viper.GetStringMap("dn")
	for ldap, _ := range ldapmap {
		ldapuri := viper.GetString(fmt.Sprintf("ldap.%s.uri", ldap))
		ldapuser := viper.GetString(fmt.Sprintf("ldap.%s.user", ldap))
		ldappass := viper.GetString(fmt.Sprintf("ldap.%s.pass", ldap))
		for dn, _ := range dnmap {
			prefixldap := fmt.Sprintf("%s.%s.%s", prefix, ldap, dn)
			data := viper.GetStringSlice(fmt.Sprintf("dn.%s.data", dn))
			basedn := viper.GetString(fmt.Sprintf("dn.%s.dn", dn))
			ldapresult := FetchData(ldapuri, ldapuser, ldappass, basedn, "(objectclass=*)", data)
			if DEBUG {
				ShowData(graphite, prefixldap, ldapresult)
			} else {
				SentData(graphite, prefixldap, ldapresult)
			}
		}
	}
}
开发者ID:gauthierc,项目名称:cnmonitor2graphite,代码行数:33,代码来源:main.go


示例12: LoadConfigByName

// LoadConfigByName loads a config from a specific file
// Used for separating test from operational configuration
func LoadConfigByName(name string) {
	var isFatal bool
	var tmp *Config

	tmp = new(Config)

	cLock.RLock()
	isFatal = (config == nil)
	cLock.RUnlock()

	viper.SetConfigName(name)
	viper.SetConfigType("json")

	configFolder := getUserConfigFolderPath()
	viper.AddConfigPath(configFolder)
	viper.AddConfigPath(".") // default path

	if err := viper.ReadInConfig(); err != nil {
		// No config to start up on
		if isFatal {
			log.Debugf("Looking for config in: %s", configFolder)
			panic(err)
		} else {
			log.Errorf("Failed to load configuration from %s\n", name)
			return
		}
	}

	log.Infof("Config file found: %s\n", viper.ConfigFileUsed())

	viper.Unmarshal(tmp)
	sanitize(tmp)

	// TODO viper can reload config too. Remove this?
	// Nope, the versioning is so we can trigger reloading of keys
	cLock.Lock()
	if config == nil {
		tmp.Version = 1
	} else {
		tmp.Version = config.Version + 1
	}

	config = tmp
	cLock.Unlock()

	log.Infof("Success loading configuration ver %d from %s", config.Version, viper.ConfigFileUsed())
}
开发者ID:livenson,项目名称:fox,代码行数:49,代码来源:Config.go


示例13: renderAndWritePage

func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layouts ...string) error {
	renderBuffer := bp.GetBuffer()
	defer bp.PutBuffer(renderBuffer)

	err := s.render(name, d, renderBuffer, layouts...)

	outBuffer := bp.GetBuffer()
	defer bp.PutBuffer(outBuffer)

	transformLinks := transform.NewEmptyTransforms()

	if viper.GetBool("RelativeURLs") || viper.GetBool("CanonifyURLs") {
		transformLinks = append(transformLinks, transform.AbsURL)
	}

	if s.Running() && viper.GetBool("watch") && !viper.GetBool("DisableLiveReload") {
		transformLinks = append(transformLinks, transform.LiveReloadInject)
	}

	var path []byte

	if viper.GetBool("RelativeURLs") {
		translated, err := s.PageTarget().(target.OptionalTranslator).TranslateRelative(dest)
		if err != nil {
			return err
		}
		path = []byte(helpers.GetDottedRelativePath(translated))
	} else if viper.GetBool("CanonifyURLs") {
		s := viper.GetString("BaseURL")
		if !strings.HasSuffix(s, "/") {
			s += "/"
		}
		path = []byte(s)
	}

	transformer := transform.NewChain(transformLinks...)
	transformer.Apply(outBuffer, renderBuffer, path)

	if outBuffer.Len() == 0 {
		jww.WARN.Printf("%q is rendered empty\n", dest)
		if dest == "/" {
			jww.ERROR.Println("=============================================================")
			jww.ERROR.Println("Your rendered home page is blank: /index.html is zero-length")
			jww.ERROR.Println(" * Did you specify a theme on the command-line or in your")
			jww.ERROR.Printf("   %q file?  (Current theme: %q)\n", filepath.Base(viper.ConfigFileUsed()), viper.GetString("Theme"))
			if !viper.GetBool("Verbose") {
				jww.ERROR.Println(" * For more debugging information, run \"hugo -v\"")
			}
			jww.ERROR.Println("=============================================================")
		}
	}

	if err == nil {
		if err = s.WriteDestPage(dest, outBuffer); err != nil {
			return err
		}
	}
	return err
}
开发者ID:michaelsync,项目名称:hugo,代码行数:59,代码来源:site.go


示例14: initConfig

// initConfig reads in config file and ENV variables if set.
func initConfig(file string) error {
	if file == "" {
		config.SetConfigName(".romana") // name of config file (without extension)
		config.AddConfigPath("$HOME")   // adding home directory as first search path
	} else {
		config.SetConfigFile(file)    // name of config file
		config.AddConfigPath("$HOME") // adding home directory as first search path
	}
	config.AutomaticEnv() // read in environment variables that match

	// If a config file is found, read it in.
	err := config.ReadInConfig()
	if err != nil {
		log.Println("Error using config file:", config.ConfigFileUsed())
		return err
	}

	log.Println("Using config file:", config.ConfigFileUsed())
	return nil
}
开发者ID:romana,项目名称:core,代码行数:21,代码来源:main.go


示例15: LoadConfigByPathWOExtension

// LoadConfigByName loads a config from a specific file
// Used for separating test from operational configuration
func LoadConfigByPathWOExtension(name string) {
	var isFatal bool
	var tmp *Config

	tmp = new(Config)

	cLock.RLock()
	isFatal = (config == nil)
	cLock.RUnlock()
	viper.SetConfigName(name)
	viper.SetConfigType("json")

	userConfigFolder := getUserConfigFolderPath()
	configFolder := getConfigFolderPath()

	if userConfigFolder != "" {
		viper.AddConfigPath(userConfigFolder) // user's own personal config file
	}
	if configFolder != "" {
		viper.AddConfigPath(configFolder) // General fallback config file
	}

	if err := viper.ReadInConfig(); err != nil {
		// No config to start up on
		if isFatal {
			log.Debugf("Failed to find config in: %s (user) or %s (fallback)",
				userConfigFolder, configFolder)
			panic(err)
		} else {
			log.Errorf("Failed to load configuration from %s\n", name)
			return
		}
	}

	viper.Unmarshal(tmp)
	sanitize(tmp)

	cLock.Lock()
	if config == nil {
		tmp.Version = 1
	} else {
		tmp.Version = config.Version + 1
	}

	config = tmp
	cLock.Unlock()

	log.WithFields(log.Fields{
		"path":        viper.ConfigFileUsed(),
		"confVersion": config.Version,
	}).Info("Success loading configuration")

}
开发者ID:e-gov,项目名称:fox,代码行数:55,代码来源:Config.go


示例16: initConfig

// initConfig reads in config file and ENV variables if set.
func initConfig() {
	// https://github.com/spf13/viper/commit/5619c0 changes the behaviour
	// of SetConfigFile and SetConfigName, thus SetConfigName should come
	// before SetConfigFile.
	config.SetConfigName(".romana") // name of config file (without extension)
	config.AddConfigPath("$HOME")   // adding home directory as first search path

	if cfgFile != "" { // enable ability to specify config file via flag
		config.SetConfigFile(cfgFile)
	}

	config.AutomaticEnv() // read in environment variables that match

	// If a config file is found, read it in.
	err := config.ReadInConfig()
	setLogOutput()
	if err != nil {
		log.Println("Error using config file:", config.ConfigFileUsed())
	} else {
		log.Println("Using config file:", config.ConfigFileUsed())
	}
}
开发者ID:romana,项目名称:core,代码行数:23,代码来源:root.go


示例17: initConfig

// initConfig reads in config file and ENV variables if set.
func initConfig() {
	if cfgFile != "" {
		viper.SetConfigFile(cfgFile)
	}

	viper.SetConfigName(".ttntool")
	viper.AddConfigPath("$HOME")
	viper.AutomaticEnv()

	if err := viper.ReadInConfig(); err == nil {
		log.WithField("file", viper.ConfigFileUsed()).Debug("Using config file")
	}
}
开发者ID:batulzii,项目名称:ttntool,代码行数:14,代码来源:root.go


示例18: initConfig

func initConfig() {
	if cfgFile != "" {
		viper.SetConfigFile(cfgFile)
	}

	viper.SetConfigName(".nag")
	viper.AddConfigPath("$HOME")
	viper.AutomaticEnv()

	if err := viper.ReadInConfig(); err == nil {
		log.Println("Using config file:", viper.ConfigFileUsed())
	}
}
开发者ID:garthk,项目名称:nag,代码行数:13,代码来源:root.go


示例19: init

// TODO: Need to look at whether this is just too much going on.
func init() {
	// enable ability to specify config file via flag
	RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.trackello.yaml)")
	if cfgFile != "" {
		viper.SetConfigFile(cfgFile)
	}
	viper.SetConfigName(".trackello") // name of config file (without extension)

	// Set Environment Variables
	viper.SetEnvPrefix("trackello")
	viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) // replace environment variables to underscore (_) from hyphen (-)
	if err := viper.BindEnv("appkey", trackello.TRACKELLO_APPKEY); err != nil {
		panic(err)
	}
	if err := viper.BindEnv("token", trackello.TRACKELLO_TOKEN); err != nil {
		panic(err)
	}
	if err := viper.BindEnv("board", trackello.TRACKELLO_PREFERRED_BOARD); err != nil {
		panic(err)
	}
	viper.AutomaticEnv() // read in environment variables that match every time Get() is called

	// Add Configuration Paths
	if cwd, err := os.Getwd(); err == nil {
		viper.AddConfigPath(cwd)
	}
	viper.AddConfigPath("$HOME") // adding home directory as first search path

	// If a config file is found, read it in.
	if err := viper.ReadInConfig(); err == nil {
		fmt.Println("Using config file:", viper.ConfigFileUsed())
	}

	RootCmd.AddCommand(configCmd)

	RootCmd.PersistentFlags().StringVar(&trelloAppKey, "appkey", "", "Trello Application Key")
	if err := viper.BindPFlag("appkey", RootCmd.PersistentFlags().Lookup("appkey")); err != nil {
		panic(err)
	}
	RootCmd.PersistentFlags().StringVar(&trelloToken, "token", "", "Trello Token")
	if err := viper.BindPFlag("token", RootCmd.PersistentFlags().Lookup("token")); err != nil {
		panic(err)
	}
	RootCmd.PersistentFlags().StringVar(&preferredBoard, "board", "", "Preferred Board ID")
	if err := viper.BindPFlag("board", RootCmd.PersistentFlags().Lookup("board")); err != nil {
		panic(err)
	}
	viper.RegisterAlias("preferredBoard", "board")
}
开发者ID:klauern,项目名称:trackello,代码行数:50,代码来源:config.go


示例20: ConfigInit

// Read in config file and ENV variables if set.
func ConfigInit() {
	viper.SetConfigType(fileType)
	if ConfigFile != "" { // enable ability to specify config file via flag
		viper.SetConfigFile(ConfigFile)
	}

	viper.SetConfigName(fileName) // name of config file (without extension)
	viper.AddConfigPath(filePath) // adding home directory as first search path
	viper.AutomaticEnv()          // read in environment variables that match

	// If a config file is found, read it in.
	if err := viper.ReadInConfig(); err == nil {
		logger.Debug("Using config file: " + viper.ConfigFileUsed())
	}
}
开发者ID:highrisehq,项目名称:github-issues,代码行数:16,代码来源:config.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang viper.Get函数代码示例发布时间:2022-05-28
下一篇:
Golang viper.BindPFlags函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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