本文整理汇总了Golang中github.com/spf13/viper.AddConfigPath函数的典型用法代码示例。如果您正苦于以下问题:Golang AddConfigPath函数的具体用法?Golang AddConfigPath怎么用?Golang AddConfigPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AddConfigPath函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: LoadConfig
// LoadConfig loads the config into the Config Struct and returns the // ConfigStruct object. Will load from environmental variables (all caps) if we
// set a flag to true.
func LoadConfig() ConfigStruct {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("../")
viper.AddConfigPath("/etc/")
viper.AddConfigPath("$GOPATH/src/github.com/GrappigPanda/notorious/")
err := viper.ReadInConfig()
if err != nil {
panic("Failed to open config file")
}
if viper.GetBool("UseEnvVariables") == true {
viper.AutomaticEnv()
viper.BindEnv("dbuser")
}
whitelist, err := strconv.ParseBool(viper.Get("whitelist").(string))
if err != nil {
whitelist = false
}
return loadSQLOptions(whitelist)
}
开发者ID:GrappigPanda,项目名称:notorious,代码行数:27,代码来源:config.go
示例2: init
func init() {
viper.SetConfigName("telebot")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("$HOME/.telebot")
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
dsn = fmt.Sprintf("%s:%[email protected](%s:%s)/%s?charset=utf8",
viper.GetString("mysql.telebot.user"),
viper.GetString("mysql.telebot.password"),
viper.GetString("mysql.telebot.host"),
viper.GetString("mysql.telebot.port"),
viper.GetString("mysql.telebot.dbname"))
db, err = sql.Open("mysql", dsn)
checkErr(err)
err = db.Ping()
checkErr(err)
go func() {
tick := time.Tick(rTime * time.Second)
for range tick {
if err := db.Ping(); err != nil {
log.Println("Connection to DB lost (try reconnect after", rTime, "seconds)")
}
}
}()
}
开发者ID:McLeod095,项目名称:telebot,代码行数:33,代码来源:models.go
示例3: init
func init() {
//Begin cobra configuration
RootCommand.PersistentFlags().StringVarP(&server, "server", "s", "localhost", "Server to connect to, separate multiple servers with a \",\"")
RootCommand.PersistentFlags().StringVarP(&keyspace, "keyspace", "k", "cassfs", "Keyspace to use for cassandra")
RootCommand.PersistentFlags().StringVar(&statedir, "statedir", "/var/run/cassfs", "Directory to use for state")
RootCommand.PersistentFlags().IntVarP(&owner, "owner", "o", 1, "Owner ID")
RootCommand.PersistentFlags().StringVarP(&environment, "environment", "e", "production", "Environment to mount")
RootCommand.PersistentFlags().Bool("debug", false, "Enable debugging")
//Begin viper configuration
viper.SetEnvPrefix("CASSFS")
viper.AutomaticEnv()
//End viper configuration
//Read from a config file
viper.SetConfigName("cassfs")
viper.SetConfigType("yaml")
viper.AddConfigPath("/etc/cassfs")
viper.AddConfigPath("$HOME/.cassfs")
viper.AddConfigPath(".")
//Begin viper/cobra integration
viper.BindPFlag("server", RootCommand.PersistentFlags().Lookup("server"))
viper.BindPFlag("statedir", RootCommand.PersistentFlags().Lookup("statedir"))
viper.BindPFlag("keyspace", RootCommand.PersistentFlags().Lookup("keyspace"))
viper.BindPFlag("owner", RootCommand.PersistentFlags().Lookup("owner"))
viper.BindPFlag("environment", RootCommand.PersistentFlags().Lookup("environment"))
viper.BindPFlag("debug", RootCommand.PersistentFlags().Lookup("debug"))
}
开发者ID:cgt212,项目名称:cassfs,代码行数:26,代码来源:root.go
示例4: InitializeConfig
// InitializeConfig initializes a config file with sensible default configuration flags.
func InitializeConfig() {
viper.SetConfigName("grasshopper") // name of config file (without extension)
viper.AddConfigPath("/etc/grasshopper.d/") // path to look for the config file
viper.AddConfigPath("$HOME/.grasshopper.d") // call multiple times to add many search paths
viper.AddConfigPath(".") // optionally look for config in the working directory
// read config from storage
err := viper.ReadInConfig() // FIXME
if err != nil {
jww.INFO.Println("Unable to locate Config file. I will fall back to my defaults...")
}
// default settings
viper.SetDefault("Verbose", false)
viper.SetDefault("DryRun", false)
viper.SetDefault("DoLog", true)
// bind config to command flags
if grasshopperCmdV.PersistentFlags().Lookup("verbose").Changed {
viper.Set("Verbose", Verbose)
}
if grasshopperCmdV.PersistentFlags().Lookup("log").Changed {
viper.Set("DoLog", DoLog)
}
}
开发者ID:vpavlin,项目名称:grasshopper,代码行数:26,代码来源:grasshopper.go
示例5: configInit
func configInit() {
viper.SetEnvPrefix("srb")
var configPath string
flag.StringVar(&configPath, "config", "", "Path of configuration file without name (name must be config.yml)")
flag.Parse()
if len(configPath) > 0 {
viper.AddConfigPath(configPath)
}
configPath = os.Getenv("SRB_CONFIG")
if len(configPath) > 0 {
viper.AddConfigPath(configPath)
}
viper.AddConfigPath("/etc/slack-redmine-bot/")
viper.AddConfigPath(".")
viper.SetConfigName("config")
viper.SetConfigType("yaml")
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Error in config file. %s \n", err))
}
}
开发者ID:muxx,项目名称:slack-redmine-bot,代码行数:28,代码来源:main.go
示例6: init
func init() {
jww.SetLogThreshold(jww.LevelTrace)
jww.SetStdoutThreshold(jww.LevelInfo)
log.Println("initing config ...")
viper.SetConfigName("zookeeper-helper")
viper.AddConfigPath("./")
viper.AddConfigPath("$HOME/.omega/")
viper.AddConfigPath("/etc/omega/")
viper.SetConfigType("yaml")
if err := viper.ReadInConfig(); err != nil {
log.Panicln("can't read config file:", err)
}
initDefault()
if err := viper.Unmarshal(&pairs); err != nil {
log.Panicln("can't covert to config pairs: ", err)
}
if !pairs.Debugging {
jww.SetLogThreshold(jww.LevelError)
jww.SetStdoutThreshold(jww.LevelError)
}
log.Printf("initialized config pairs: %+v\n", pairs)
}
开发者ID:Dataman-Cloud,项目名称:zookeeper-helper,代码行数:29,代码来源:config.go
示例7: InitConfig
func InitConfig(configFile string) {
SetDefaults()
if configFile != "" {
if _, err := os.Stat(configFile); os.IsNotExist(err) {
log.WithFields(log.Fields{"file": configFile}).Fatal("Config file does not exist")
}
// Load the config file if supplied
viper.SetConfigFile(configFile)
} else {
// Otherwise use the defaults
viper.SetConfigName("agent")
viper.AddConfigPath("/etc/reeve")
viper.AddConfigPath("$HOME/.reeve")
}
err := viper.ReadInConfig()
if err != nil {
// Check if we got an unsupported config error
// If so it means that no files were found, and we can just skip it using our defaults
_, ok := err.(viper.UnsupportedConfigError)
if !ok {
log.WithError(err).Fatal("Could not read config")
}
log.Debug("No config file available, using all defaults")
}
}
开发者ID:borgstrom,项目名称:reeve,代码行数:29,代码来源:config.go
示例8: loadConfig
func loadConfig() {
stormpath.InitLog()
viper.SetConfigType("yaml")
viper.AutomaticEnv()
//Load bundled default config
defaultConfig, err := Asset("config/web.stormpath.yaml")
if err != nil {
stormpath.Logger.Panicf("[ERROR] Couldn't load default bundle configuration: %s", err)
}
viper.ReadConfig(bytes.NewBuffer(defaultConfig))
//Merge users custom configuration
viper.SetConfigFile("stormpath.yaml")
viper.AddConfigPath("~/.stormpath/")
viper.AddConfigPath(".")
err = viper.MergeInConfig()
if err != nil {
stormpath.Logger.Println("[WARN] User didn't provide custom configuration")
}
Config.Produces = viper.GetStringSlice("stormpath.web.produces")
Config.BasePath = viper.GetString("stormpath.web.basePath")
loadSocialConfig()
loadCookiesConfig()
loadEndpointsConfig()
loadOAuth2Config()
}
开发者ID:jxstanford,项目名称:stormpath-sdk-go,代码行数:31,代码来源:config.go
示例9: initConfig
func initConfig() {
// defaults
viper.SetDefault("adminroot", "/admin/") // front end location of admin
viper.SetDefault("admindir", "./admin") // location of admin assets (relative to site directory)
viper.SetDefault("contentdir", "content")
// config name and location
viper.SetConfigName("config")
viper.AddConfigPath("/etc/topiary")
viper.AddConfigPath(".")
// read config
err := viper.ReadInConfig()
if err != nil {
fmt.Println("No topiary config found. Using defaults.")
}
// watch config ; TODO : config to turn this on/off
viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
fmt.Println("Config file changed:", e.Name)
})
}
开发者ID:topiary-io,项目名称:topiary,代码行数:25,代码来源:config.go
示例10: init
func init() {
Root.PersistentFlags().StringVar(&CfgFile, "config", "", "config file (default is path/config.yaml|json|toml)")
Root.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output")
Root.Flags().IntVarP(&Port, "port", "p", 2714, "port number to run on")
Root.Flags().StringVarP(&DBName, "dbname", "d", "kaiju", "name of the database")
Root.Flags().StringVarP(&Host, "host", "h", "", "host to run on")
Root.Flags().IntVar(&DBPort, "dbport", 27017, "port to access mongoDB")
Root.Flags().StringVar(&DBHost, "dbhost", "localhost", "host where mongoDB is")
viper.SetConfigName(CfgFile)
viper.AddConfigPath("./")
viper.AddConfigPath("/etc/kaiju/")
err := viper.ReadInConfig()
if err != nil {
jww.ERROR.Println("Config not found... using only defaults, stuff may not work")
}
viper.Set("port", Port)
viper.Set("host", Host)
viper.Set("dbname", DBName)
viper.Set("dbport", DBPort)
viper.Set("dbhost", DBHost)
viper.Set("verbose", Verbose)
db_init()
}
开发者ID:giorgil,项目名称:kaiju,代码行数:26,代码来源:kaiju.go
示例11: main
func main() {
filter := &logutils.LevelFilter{
Levels: []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERROR"},
MinLevel: logutils.LogLevel("INFO"),
Writer: os.Stderr,
}
log.SetOutput(filter)
viper.SetConfigName("Rigfile")
viper.AddConfigPath("$HOME/.rigger/")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
if _, ok := err.(viper.UnsupportedConfigError); ok {
log.Printf("[ERROR] No Rigfile exists.")
os.Exit(1)
} else {
log.Printf("[ERROR] %s", err)
}
}
var cmdUp = &cobra.Command{
Use: "up",
Short: "Create my infrastructure",
Long: `Do lots of work`,
Run: func(cmd *cobra.Command, args []string) {
log.Printf("[INFO] Rigger lifting!")
},
}
var rootCmd = &cobra.Command{Use: "rigger"}
rootCmd.AddCommand(cmdUp)
rootCmd.Execute()
}
开发者ID:sgoings,项目名称:rigger,代码行数:35,代码来源:rigger.go
示例12: LoadGlobalConfig
// LoadGlobalConfig loads Hugo configuration into the global Viper.
func LoadGlobalConfig(relativeSourcePath, configFilename string) error {
if relativeSourcePath == "" {
relativeSourcePath = "."
}
viper.AutomaticEnv()
viper.SetEnvPrefix("hugo")
viper.SetConfigFile(configFilename)
// See https://github.com/spf13/viper/issues/73#issuecomment-126970794
if relativeSourcePath == "" {
viper.AddConfigPath(".")
} else {
viper.AddConfigPath(relativeSourcePath)
}
err := viper.ReadInConfig()
if err != nil {
if _, ok := err.(viper.ConfigParseError); ok {
return err
}
return fmt.Errorf("Unable to locate Config file. Perhaps you need to create a new site.\n Run `hugo help new` for details. (%s)\n", err)
}
viper.RegisterAlias("indexes", "taxonomies")
loadDefaultSettings()
return nil
}
开发者ID:tubo028,项目名称:hugo,代码行数:30,代码来源:config.go
示例13: init
func init() {
viper.SetConfigName("dkron") // name of config file (without extension)
viper.AddConfigPath("/etc/dkron") // call multiple times to add many search paths
viper.AddConfigPath("$HOME/.dkron") // call multiple times to add many search paths
viper.AddConfigPath("./config") // call multiple times to add many search paths
viper.SetEnvPrefix("dkron") // will be uppercased automatically
viper.AutomaticEnv()
}
开发者ID:oldmantaiter,项目名称:dkron,代码行数:8,代码来源:config.go
示例14: main
func main() {
// For environment variables.
viper.SetEnvPrefix(cmdRoot)
viper.AutomaticEnv()
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)
// Define command-line flags that are valid for all peer commands and
// subcommands.
mainFlags := mainCmd.PersistentFlags()
mainFlags.BoolVarP(&versionFlag, "version", "v", false, "Display current version of fabric peer server")
mainFlags.String("logging-level", "", "Default logging level and overrides, see core.yaml for full syntax")
viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level"))
testCoverProfile := ""
mainFlags.StringVarP(&testCoverProfile, "test.coverprofile", "", "coverage.cov", "Done")
var alternativeCfgPath = os.Getenv("PEER_CFG_PATH")
if alternativeCfgPath != "" {
logger.Infof("User defined config file path: %s", alternativeCfgPath)
viper.AddConfigPath(alternativeCfgPath) // Path to look for the config file in
} else {
viper.AddConfigPath("./") // Path to look for the config file in
// Path to look for the config file in based on GOPATH
gopath := os.Getenv("GOPATH")
for _, p := range filepath.SplitList(gopath) {
peerpath := filepath.Join(p, "src/github.com/hyperledger/fabric/peer")
viper.AddConfigPath(peerpath)
}
}
// Now set the configuration file.
viper.SetConfigName(cmdRoot) // Name of config file (without extension)
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error when reading %s config file: %s\n", cmdRoot, err))
}
mainCmd.AddCommand(version.Cmd())
mainCmd.AddCommand(node.Cmd())
mainCmd.AddCommand(network.Cmd())
mainCmd.AddCommand(chaincode.Cmd())
runtime.GOMAXPROCS(viper.GetInt("peer.gomaxprocs"))
// Init the crypto layer
if err := crypto.Init(); err != nil {
panic(fmt.Errorf("Failed to initialize the crypto layer: %s", err))
}
// On failure Cobra prints the usage message and error string, so we only
// need to exit with a non-0 status
if mainCmd.Execute() != nil {
os.Exit(1)
}
logger.Info("Exiting.....")
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:58,代码来源:main.go
示例15: initConfig
func initConfig() {
if CfgFile != "" {
viper.SetConfigFile(CfgFile)
}
viper.SetConfigName("config")
viper.AddConfigPath("/etc/dagobah/")
viper.AddConfigPath("$HOME/.dagobah/")
viper.ReadInConfig()
}
开发者ID:LC2010,项目名称:firstGoApp-Planet,代码行数:9,代码来源:planet.go
示例16: setupTestConfig
func setupTestConfig() {
viper.SetConfigName("openchain") // name of config file (without extension)
viper.AddConfigPath("./") // path to look for the config file in
viper.AddConfigPath("./..") // path to look for the config file in
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
}
开发者ID:tenc,项目名称:obc-peer-pre-public,代码行数:9,代码来源:api_test.go
示例17: initConfig
func initConfig() {
if CfgFile != "" {
viper.SetConfigFile(CfgFile)
}
viper.SetConfigName("config") // name of config file (without extension)
viper.AddConfigPath("/etc/dagobah/") // path to look for the config file in
viper.AddConfigPath("$HOME/.dagobah/") // call multiple times to add many search paths
viper.ReadInConfig()
}
开发者ID:yangzhares,项目名称:dagobah,代码行数:9,代码来源:dagobah.go
示例18: init
func init() {
viper.SetConfigName("config")
viper.AddConfigPath(".")
viper.AddConfigPath("$HOME/.futfut")
viper.AddConfigPath("/")
err := viper.ReadInConfig()
if err != nil {
logger.Fatal("No configuration file loaded - exiting")
}
}
开发者ID:clausthrane,项目名称:futfut,代码行数:10,代码来源:config.go
示例19: Config
func Config() {
viper.SetConfigName("config")
viper.AddConfigPath("$HOME/." + Name)
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
}
开发者ID:Sitback,项目名称:helm,代码行数:10,代码来源:config.go
示例20: readConfig
func readConfig() {
path, _ := osext.ExecutableFolder()
viper.AddConfigPath("/etc/eremetic")
viper.AddConfigPath(path)
viper.AutomaticEnv()
viper.SetConfigName("eremetic")
viper.SetDefault("loglevel", "debug")
viper.SetDefault("database", "db/eremetic.db")
viper.ReadInConfig()
}
开发者ID:mommel,项目名称:eremetic,代码行数:10,代码来源:eremetic.go
注:本文中的github.com/spf13/viper.AddConfigPath函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论