本文整理汇总了Golang中github.com/spf13/viper.GetStringMap函数的典型用法代码示例。如果您正苦于以下问题:Golang GetStringMap函数的具体用法?Golang GetStringMap怎么用?Golang GetStringMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetStringMap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: initializeSiteInfo
func (s *Site) initializeSiteInfo() {
params := viper.GetStringMap("Params")
permalinks := make(PermalinkOverrides)
for k, v := range viper.GetStringMapString("Permalinks") {
permalinks[k] = PathPattern(v)
}
s.Info = SiteInfo{
BaseUrl: template.URL(helpers.SanitizeUrlKeepTrailingSlash(viper.GetString("BaseUrl"))),
Title: viper.GetString("Title"),
Author: viper.GetStringMap("author"),
LanguageCode: viper.GetString("languagecode"),
Copyright: viper.GetString("copyright"),
DisqusShortname: viper.GetString("DisqusShortname"),
BuildDrafts: viper.GetBool("BuildDrafts"),
canonifyUrls: viper.GetBool("CanonifyUrls"),
Pages: &s.Pages,
Recent: &s.Pages,
Menus: &s.Menus,
Params: params,
Permalinks: permalinks,
Data: &s.Data,
}
}
示例2: initializeSiteInfo
func (s *Site) initializeSiteInfo() {
params := viper.GetStringMap("Params")
permalinks := make(PermalinkOverrides)
for k, v := range viper.GetStringMapString("Permalinks") {
permalinks[k] = PathPattern(v)
}
s.Info = SiteInfo{
BaseURL: template.URL(helpers.SanitizeURLKeepTrailingSlash(viper.GetString("BaseURL"))),
Title: viper.GetString("Title"),
Author: viper.GetStringMap("author"),
Social: viper.GetStringMapString("social"),
LanguageCode: viper.GetString("languagecode"),
Copyright: viper.GetString("copyright"),
DisqusShortname: viper.GetString("DisqusShortname"),
GoogleAnalytics: viper.GetString("GoogleAnalytics"),
RSSLink: s.permalinkStr(viper.GetString("RSSUri")),
BuildDrafts: viper.GetBool("BuildDrafts"),
canonifyURLs: viper.GetBool("CanonifyURLs"),
preserveTaxonomyNames: viper.GetBool("PreserveTaxonomyNames"),
Pages: &s.Pages,
Menus: &s.Menus,
Params: params,
Permalinks: permalinks,
Data: &s.Data,
}
}
示例3: 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)
}
}
}
}
示例4: NewBlackfriday
// NewBlackfriday creates a new Blackfriday filled with site config or some sane defaults.
func NewBlackfriday() *Blackfriday {
combinedParam := map[string]interface{}{
"smartypants": true,
"angledQuotes": false,
"fractions": true,
"hrefTargetBlank": false,
"smartDashes": true,
"latexDashes": true,
"plainIDAnchors": true,
"sourceRelativeLinks": false,
"sourceRelativeLinksProjectFolder": "/docs/content",
}
siteParam := viper.GetStringMap("blackfriday")
if siteParam != nil {
siteConfig := cast.ToStringMap(siteParam)
for key, value := range siteConfig {
combinedParam[key] = value
}
}
combinedConfig := &Blackfriday{}
if err := mapstructure.Decode(combinedParam, combinedConfig); err != nil {
jww.FATAL.Printf("Failed to get site rendering config\n%s", err.Error())
}
return combinedConfig
}
示例5: GetStringMapBool
func GetStringMapBool(key, mkey string) (error, bool) {
m := viper.GetStringMap(key)[mkey]
if m != nil {
return nil, m.(bool)
}
return errors.New("can't found:" + key + "," + mkey), false
}
示例6: getMenusFromConfig
func (s *Site) getMenusFromConfig() Menus {
ret := Menus{}
if menus := viper.GetStringMap("menu"); menus != nil {
for name, menu := range menus {
m, err := cast.ToSliceE(menu)
if err != nil {
jww.ERROR.Printf("unable to process menus in site config\n")
jww.ERROR.Println(err)
} else {
for _, entry := range m {
jww.DEBUG.Printf("found menu: %q, in site config\n", name)
menuEntry := MenuEntry{Menu: name}
ime, err := cast.ToStringMapE(entry)
if err != nil {
jww.ERROR.Printf("unable to process menus in site config\n")
jww.ERROR.Println(err)
}
menuEntry.MarshallMap(ime)
if ret[name] == nil {
ret[name] = &Menu{}
}
*ret[name] = ret[name].Add(&menuEntry)
}
}
}
return ret
}
return ret
}
示例7: getRenderingConfig
func (p *Page) getRenderingConfig() *helpers.Blackfriday {
p.renderingConfigInit.Do(func() {
pageParam := p.GetParam("blackfriday")
siteParam := viper.GetStringMap("blackfriday")
combinedParam := siteParam
if pageParam != nil {
combinedParam = make(map[string]interface{})
for k, v := range siteParam {
combinedParam[k] = v
}
pageConfig := cast.ToStringMap(pageParam)
for key, value := range pageConfig {
combinedParam[key] = value
}
}
p.renderingConfig = helpers.NewBlackfriday()
if err := mapstructure.Decode(combinedParam, p.renderingConfig); err != nil {
jww.FATAL.Printf("Failed to get rendering config for %s:\n%s", p.BaseFileName(), err.Error())
}
})
return p.renderingConfig
}
示例8: main
func main() {
// config defaults
viper.SetDefault("SigningKey", "change me in config/app.toml")
viper.SetDefault("Port", "8888")
viper.SetDefault("Database", "postgresql")
viper.SetConfigType("toml")
viper.SetConfigName("app")
viper.AddConfigPath("./config/")
// TODO better error message
err := viper.ReadInConfig()
if err != nil {
fmt.Print(fmt.Errorf("Fatal error config file: %s \n", err))
fmt.Println("Config path is ./config/, and name should be app.toml")
fmt.Println("Using defaults")
}
// TODO: check toml for nested propeties
// TODO: Handle config in a separate module? file?
dbConfig := viper.GetStringMap("Database")
dbName := dbConfig["Name"]
dbUser := dbConfig["User"]
// fmt.Sprintf("user=%s dbname=%s sslmode=disable", dbUser, dbName)
dbOptions := db.Options{
Driver: "postgres",
Params: fmt.Sprintf("user=%s dbname=%s sslmode=disable", dbUser, dbName),
}
dbConnection := db.Connect(dbOptions)
app := NewApp([]byte(viper.GetString("SigningKey")), dbConnection)
port := viper.GetString("Port")
log.Printf("Serving on port: %s\n", port)
app.E.Run(":" + port)
}
示例9: NewState
// NewState constructs a new State. This Initializes encapsulated state implementation
func NewState() *State {
stateImplName := viper.GetString("ledger.state.dataStructure.name")
stateImplConfigs := viper.GetStringMap("ledger.state.dataStructure.configs")
if len(stateImplName) == 0 {
stateImplName = detaultStateImpl
stateImplConfigs = nil
}
logger.Info("Initializing state implementation [%s]", stateImplName)
switch stateImplName {
case "buckettree":
stateImpl = buckettree.NewStateImpl()
case "trie":
stateImpl = trie.NewStateTrie()
case "raw":
stateImpl = raw.NewRawState()
default:
panic(fmt.Errorf("Error during initialization of state implementation. State data structure '%s' is not valid.", stateImplName))
}
err := stateImpl.Initialize(stateImplConfigs)
if err != nil {
panic(fmt.Errorf("Error during initialization of state implementation: %s", err))
}
deltaHistorySize := viper.GetInt("ledger.state.deltaHistorySize")
if deltaHistorySize < 0 {
panic(fmt.Errorf("Delta history size must be greater than or equal to 0. Current value is %d.", deltaHistorySize))
}
return &State{stateImpl, statemgmt.NewStateDelta(), statemgmt.NewStateDelta(), "", make(map[string][]byte),
false, uint64(deltaHistorySize)}
}
示例10: TestConfigInit
func TestConfigInit(t *testing.T) {
configs := viper.GetStringMap("ledger.state.dataStructure.configs")
t.Logf("Configs loaded from yaml = %#v", configs)
testDBWrapper.CleanDB(t)
stateImpl := NewStateImpl()
stateImpl.Initialize(configs)
testutil.AssertEquals(t, conf.getNumBucketsAtLowestLevel(), configs[ConfigNumBuckets])
testutil.AssertEquals(t, conf.getMaxGroupingAtEachLevel(), configs[ConfigMaxGroupingAtEachLevel])
}
示例11: RenderSitemap
func (s *Site) RenderSitemap() error {
if viper.GetBool("DisableSitemap") {
return nil
}
sitemapDefault := parseSitemap(viper.GetStringMap("Sitemap"))
optChanged := false
n := s.NewNode()
// Prepend homepage to the list of pages
pages := make(Pages, 0)
page := &Page{}
page.Date = s.Info.LastChange
page.Site = &s.Info
page.Url = "/"
pages = append(pages, page)
pages = append(pages, s.Pages...)
n.Data["Pages"] = pages
for _, page := range pages {
if page.Sitemap.ChangeFreq == "" {
page.Sitemap.ChangeFreq = sitemapDefault.ChangeFreq
}
if page.Sitemap.Priority == -1 {
page.Sitemap.Priority = sitemapDefault.Priority
}
}
// Force `UglyUrls` option to force `sitemap.xml` file name
switch s.PageTarget().(type) {
case *target.Filesystem:
s.PageTarget().(*target.PagePub).UglyUrls = true
optChanged = true
}
smLayouts := []string{"sitemap.xml", "_default/sitemap.xml", "_internal/_default/sitemap.xml"}
b, err := s.renderXML("sitemap", n, s.appendThemeTemplates(smLayouts)...)
if err != nil {
return err
}
if err := s.WriteDestFile("sitemap.xml", b); err != nil {
return err
}
if optChanged {
s.PageTarget().(*target.PagePub).UglyUrls = viper.GetBool("UglyUrls")
}
return nil
}
示例12: GetServer
func GetServer(key string) string {
env := viper.Get("env")
confEnv := viper.GetStringMap("development")
switch env {
case "development":
value, _ := mapServer(confEnv)[key].(string)
return value
case "production":
confEnv := viper.GetStringMap("production")
value, _ := mapServer(confEnv)[key].(string)
return value
case "testing":
confEnv := viper.GetStringMap("testing")
value, _ := mapServer(confEnv)[key].(string)
return value
default:
log.Panic("Missing config environment")
}
return ""
}
示例13: init
func init() {
flag.Parse()
config.SetConfigFile(*configFileName)
err := config.ReadInConfig()
if err != nil {
panic("Config file not found")
}
logConfig := config.GetStringMap("log")
initLog(logConfig)
}
示例14: GetCliOrConfig
func GetCliOrConfig(c string, cli interface{}) interface{} {
val := cli
if cli == "" {
if strings.Contains(c, "/") {
s := strings.Split(c, "/")
return viper.GetStringMap(s[0])[s[1]]
} else {
return Get(c)
}
}
return val
}
示例15: startHttpTestsFromConfig
func startHttpTestsFromConfig() {
for name := range viper.GetStringMap("health_checks") {
prefix := fmt.Sprintf("health_checks.%s.", name)
testType := viper.GetString(prefix + "type")
switch testType {
case "http":
startHttpTest(getHttpConfig(name, prefix))
default:
fmt.Errorf("Cannot handle test type: %s", testType)
}
}
}