本文整理汇总了Golang中github.com/spf13/viper.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例2: main
func main() {
config.LoadConfig()
dev := viper.Sub("app.development.twitter")
fmt.Println(dev)
fmt.Println(dev.Get("consumerKey"))
consumerKey := viper.Get("app.development.twitter.consumerKey").(string)
consumerSecret := viper.Get("app.development.twitter.consumerSecret").(string)
tokenKey := viper.Get("app.development.twitter.token").(string)
tokenSecret := viper.Get("app.development.twitter.tokenSecret").(string)
config := oauth1.NewConfig(consumerKey, consumerSecret)
token := oauth1.NewToken(tokenKey, tokenSecret)
httpClient := config.Client(oauth1.NoContext, token)
client := twitter.NewClient(httpClient)
userShowParams := &twitter.UserShowParams{ScreenName: "realDonaldTrump"}
user, _, _ := client.Users.Show(userShowParams)
fmt.Printf("USERS SHOW:\n%v\n", user)
f := new(bool)
*f = false
userTimelineParams := &twitter.UserTimelineParams{ScreenName: "realDonaldTrump", Count: 1, IncludeRetweets: f}
tweets, _, _ := client.Timelines.UserTimeline(userTimelineParams)
for tweet := range tweets {
t, _ := json.MarshalIndent(tweets[tweet], "", " ")
fmt.Println(string(t))
}
}
示例3: GetConfig
// GetConfig return configuration instance
func GetConfig() Config {
config := Config{
LinguaLeo: linguaLeo{
Email: cast.ToString(viper.Get("lingualeo.email")),
Password: cast.ToString(viper.Get("lingualeo.password")),
},
}
return config
}
示例4: main
func main() {
redmine := redmine.New(
viper.GetString("redmine.url"),
viper.GetString("redmine.api_key"),
cast.ToIntSlice(viper.Get("redmine.closed_statuses")),
cast.ToIntSlice(viper.Get("redmine.high_priorities")),
)
slack := slack.New(redmine, viper.GetString("slack.token"))
slack.Listen()
}
示例5: initConfig
// initConfig reads in config file and ENV variables if set.
func initConfig() {
mutex.Lock()
if cfgFile != "" {
// enable ability to specify config file via flag
viper.SetConfigFile(cfgFile)
}
path := absPathify("$HOME")
if _, err := os.Stat(filepath.Join(path, ".hydra.yml")); err != nil {
_, _ = os.Create(filepath.Join(path, ".hydra.yml"))
}
viper.SetConfigType("yaml")
viper.SetConfigName(".hydra") // 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(`Config file not found because "%s"`, err)
fmt.Println("")
}
if err := viper.Unmarshal(c); err != nil {
fatal("Could not read config because %s.", err)
}
if consentURL, ok := viper.Get("CONSENT_URL").(string); ok {
c.ConsentURL = consentURL
}
if clientID, ok := viper.Get("CLIENT_ID").(string); ok {
c.ClientID = clientID
}
if systemSecret, ok := viper.Get("SYSTEM_SECRET").(string); ok {
c.SystemSecret = []byte(systemSecret)
}
if clientSecret, ok := viper.Get("CLIENT_SECRET").(string); ok {
c.ClientSecret = clientSecret
}
if databaseURL, ok := viper.Get("DATABASE_URL").(string); ok {
c.DatabaseURL = databaseURL
}
if c.ClusterURL == "" {
fmt.Printf("Pointing cluster at %s\n", c.GetClusterURL())
}
mutex.Unlock()
}
示例6: getTestMenuState
func getTestMenuState(s *Site, t *testing.T) *testMenuState {
menuState := &testMenuState{site: s, oldBaseURL: viper.Get("baseurl"), oldMenu: viper.Get("menu")}
menus, err := tomlToMap(CONF_MENU1)
if err != nil {
t.Fatalf("Unable to Read menus: %v", err)
}
viper.Set("menu", menus["menu"])
viper.Set("baseurl", "http://foo.local/Zoo/")
return menuState
}
示例7: loadSQLOptions
func loadSQLOptions(whitelist bool) ConfigStruct {
var sqlDeployOption string
if viper.GetBool("UseMySQL") {
sqlDeployOption = "mysql"
} else {
sqlDeployOption = "postgres"
}
var ircCfg *IRCConfig
if viper.GetBool("UseIRCNotify") {
ircCfg = loadIRCOptions()
} else {
ircCfg = nil
}
var useRSS bool
if viper.GetBool("UseRSSNotify") {
useRSS = true
} else {
useRSS = false
}
if viper.Get("dbpass").(string) != "" {
return ConfigStruct{
sqlDeployOption,
viper.Get("dbhost").(string),
viper.Get("dbport").(string),
viper.Get("dbuser").(string),
viper.Get("dbpass").(string),
viper.Get("dbname").(string),
whitelist,
ircCfg,
useRSS,
}
} else {
return ConfigStruct{
sqlDeployOption,
viper.Get("dbhost").(string),
viper.Get("dbport").(string),
viper.Get("dbuser").(string),
"",
viper.Get("dbname").(string),
whitelist,
ircCfg,
useRSS,
}
}
}
示例8: loadBundles
func loadBundles() {
target := viper.GetString("WorkingDir")
tdir := filepath.Join(target, "bundles")
if _, err := os.Stat(tdir); os.IsNotExist(err) {
return
}
bund := viper.Get("Bundles").([]Bundle)
filepath.Walk(tdir, func(path string, f os.FileInfo, err error) error {
name := filepath.Base(path)
if name == "bundles" {
return nil
}
rpath, _ := filepath.Rel(target, path)
if s, _ := os.Stat(path); s.IsDir() {
bund = append(bund, Bundle{name, rpath})
}
return nil
})
viper.Set("Bundles", bund)
}
示例9: Config
// Config returns the currently active Hugo config. This will be set
// per site (language) rendered.
func Config() ConfigProvider {
if currentConfigProvider != nil {
return currentConfigProvider
}
// Some tests rely on this. We will fix that, eventually.
return viper.Get("currentContentLanguage").(ConfigProvider)
}
示例10: SetupTest
func (suite *GitConfigTestSuite) SetupTest() {
assert := assert.New(suite.T())
viper.SetConfigFile("../../.ayi.example.yml")
err := viper.ReadInConfig()
assert.Nil(err)
assert.Equal(true, viper.Get("debug"))
}
示例11: DeactivateLongpollKillswitch
func (this *RedisStore) DeactivateLongpollKillswitch() error {
killswitchKey := viper.Get("longpoll_killswitch")
return this.redisPendingQueue.RunAsyncTimeout(5*time.Second, func(conn redis.Conn) (result interface{}, err error) {
return conn.Do("DEL", killswitchKey)
}).Error
}
示例12: ViperGetStringOrFail
// ViperGetStringOrFail returns string without any convertion
// FIXED: https://github.com/dyweb/Ayi/issues/54
func ViperGetStringOrFail(key string) (string, error) {
v := viper.Get(key)
s, ok := v.(string)
if ok {
return s, nil
}
return "", errors.Errorf("%v is not a string", v)
}
示例13: loadBoolPtr
func loadBoolPtr(key string) *bool {
val := viper.Get(key)
if val == nil {
return nil
}
b := viper.GetBool(key)
return &b
}
示例14: loadConfig
func loadConfig(c *Config) {
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
log.Error("Fatal error config file.", "error", err)
} else {
c.Alert = viper.Get("alert")
}
}
示例15: initializeSiteInfo
func (s *Site) initializeSiteInfo() {
params, ok := viper.Get("Params").(map[string]interface{})
if !ok {
params = make(map[string]interface{})
}
permalinks, ok := viper.Get("Permalinks").(PermalinkOverrides)
if !ok {
permalinks = make(PermalinkOverrides)
}
s.Info = SiteInfo{
BaseUrl: template.URL(helpers.SanitizeUrl(viper.GetString("BaseUrl"))),
Title: viper.GetString("Title"),
Recent: &s.Pages,
Params: params,
Permalinks: permalinks,
}
}