本文整理汇总了Golang中github.com/spf13/viper.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的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: 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))
}
}
开发者ID:cyarie,项目名称:trumptweets-pull,代码行数:30,代码来源:main.go
示例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
}
开发者ID:igrybkov,项目名称:leosync,代码行数:10,代码来源:config.go
示例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()
}
开发者ID:muxx,项目名称:slack-redmine-bot,代码行数:11,代码来源:main.go
示例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()
}
开发者ID:jemacom,项目名称:hydra,代码行数:53,代码来源:root.go
示例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
}
开发者ID:saturdayplace,项目名称:hugo,代码行数:14,代码来源:menu_test.go
示例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,
}
}
}
开发者ID:GrappigPanda,项目名称:notorious,代码行数:48,代码来源:config.go
示例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)
}
开发者ID:pedronasser,项目名称:garf,代码行数:26,代码来源:new.go
示例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)
}
开发者ID:digitalcraftsman,项目名称:hugo,代码行数:9,代码来源:configProvider.go
示例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"))
}
开发者ID:dyweb,项目名称:Ayi,代码行数:7,代码来源:config_test.go
示例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
}
开发者ID:mahtuag,项目名称:incus,代码行数:7,代码来源:redis_store.go
示例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)
}
开发者ID:dyweb,项目名称:Ayi,代码行数:10,代码来源:viper.go
示例13: loadBoolPtr
func loadBoolPtr(key string) *bool {
val := viper.Get(key)
if val == nil {
return nil
}
b := viper.GetBool(key)
return &b
}
开发者ID:jxstanford,项目名称:stormpath-sdk-go,代码行数:8,代码来源:config.go
示例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")
}
}
开发者ID:bradobro,项目名称:corazones,代码行数:9,代码来源:config.go
示例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,
}
}
开发者ID:h0wn0w,项目名称:hugo,代码行数:19,代码来源:site.go
示例16: Get
func (l *Language) Get(key string) interface{} {
if l == nil {
panic("language not set")
}
key = strings.ToLower(key)
if v, ok := l.params[key]; ok {
return v
}
return viper.Get(key)
}
开发者ID:tarsisazevedo,项目名称:hugo,代码行数:10,代码来源:language.go
示例17: deleteProduct
func deleteProduct(d Delete) {
if d.SKU == "" {
return
}
user := viper.Get("User")
stmt, err := db.Prepare("DELETE FROM products WHERE SKU=? AND User=?")
errHandle(err)
_, err = stmt.Exec(d.SKU, user)
errHandle(err)
}
开发者ID:SeleneSoftware,项目名称:HermesInventory,代码行数:10,代码来源:products.go
示例18: Update
func Update(coreOnly bool, securityOnly bool, checkDisabled bool) (result interface{}, err error) {
switch viper.Get("app_type") {
case "drupal":
result, err = drupalUpdate(coreOnly, securityOnly, checkDisabled)
case "wpress":
result, err = wpressUpdate(coreOnly)
default:
result, err = nil, errors.New("Not implemented", 0)
}
return result, err
}
开发者ID:Wodby,项目名称:wcli,代码行数:12,代码来源:backend.go
示例19: Revert
func Revert() (result interface{}, err error) {
switch viper.Get("app_type") {
case "drupal":
result, err = drupalRevert()
// case "wpress":
// result, err = wpressMigrate()
default:
result, err = nil, errors.New("Not implemented", 0)
}
return result, err
}
开发者ID:Wodby,项目名称:wcli,代码行数:12,代码来源:backend.go
示例20: getDateFormat
// getDateFormat gets the dateFormat value from Params. The dateFormat should
// be a valid time layout. If it isn't set, time.RFC3339 is used.
func getDateFormat() string {
params := viper.Get("params")
if params == nil {
return time.RFC3339
}
parms := params.(map[interface{}]interface{})
layout := parms["DateFormat"]
if layout == nil || layout == "" {
return time.RFC3339
}
return layout.(string)
}
开发者ID:kuruma,项目名称:hugo,代码行数:14,代码来源:version.go
注:本文中的github.com/spf13/viper.Get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论