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

Golang viper.GetStringMap函数代码示例

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

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



在下文中一共展示了GetStringMap函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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,
	}
}
开发者ID:dunn,项目名称:hugo,代码行数:25,代码来源:site.go


示例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,
	}
}
开发者ID:maruel,项目名称:hugo,代码行数:28,代码来源:site.go


示例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)
			}
		}
	}
}
开发者ID:gauthierc,项目名称:cnmonitor2graphite,代码行数:33,代码来源:main.go


示例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
}
开发者ID:xinzhi,项目名称:hugo,代码行数:30,代码来源:content.go


示例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
}
开发者ID:yiqguo,项目名称:LogCollect,代码行数:7,代码来源:config.go


示例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
}
开发者ID:johnsto,项目名称:hugo,代码行数:33,代码来源:site.go


示例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
}
开发者ID:JTrembl1,项目名称:hugo,代码行数:29,代码来源:page.go


示例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)
}
开发者ID:q1t,项目名称:movielist,代码行数:35,代码来源:main.go


示例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)}
}
开发者ID:tanyakchoon,项目名称:obc-peer,代码行数:34,代码来源:state.go


示例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])
}
开发者ID:ZhuZhengyi,项目名称:fabric,代码行数:9,代码来源:config_test.go


示例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
}
开发者ID:jaden,项目名称:hugo,代码行数:56,代码来源:site.go


示例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 ""
}
开发者ID:tatthien,项目名称:go-simple-rest,代码行数:20,代码来源:config.go


示例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)
}
开发者ID:artpar,项目名称:greconcile,代码行数:11,代码来源:main.go


示例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
}
开发者ID:jgautheron,项目名称:gocha,代码行数:12,代码来源:config.go


示例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)
		}
	}
}
开发者ID:bweston92,项目名称:vigour,代码行数:12,代码来源:start.go


示例16: loadConfigs

func loadConfigs() {
	genesisLogger.Info("Loading configurations...")
	genesis = viper.GetStringMap("ledger.blockchain.genesisBlock")
	mode = viper.GetString("chaincode.chaincoderunmode")
	genesisLogger.Info("Configurations loaded: genesis=%s, mode=[%s], deploySystemChaincodeEnabled=[%t]",
		genesis, mode, deploySystemChaincodeEnabled)
	if viper.IsSet("ledger.blockchain.deploy-system-chaincode") {
		// If the deployment of system chaincode is enabled in the configuration file return the configured value
		deploySystemChaincodeEnabled = viper.GetBool("ledger.blockchain.deploy-system-chaincode")
	} else {
		// Deployment of system chaincode is enabled by default if no configuration was specified.
		deploySystemChaincodeEnabled = true
	}
}
开发者ID:RicHernandez2,项目名称:fabric,代码行数:14,代码来源:config.go


示例17: Params

func (l *Language) Params() map[string]interface{} {
	l.paramsInit.Do(func() {
		// Merge with global config.
		// TODO(bep) consider making this part of a constructor func.

		globalParams := viper.GetStringMap("Params")
		for k, v := range globalParams {
			if _, ok := l.params[k]; !ok {
				l.params[k] = v
			}
		}
	})
	return l.params
}
开发者ID:tarsisazevedo,项目名称:hugo,代码行数:14,代码来源:language.go


示例18: initServerConfig

func initServerConfig() {
	s := viper.GetStringMap("server")

	host := s["host"]
	if host == nil {
		srv.Config.Host = defaultServerHost
	} else {
		srv.Config.Host = host.(string)
	}

	port := s["port"]
	if port == nil {
		srv.Config.Port = defaultServerPort
	} else {
		srv.Config.Port = port.(uint)
	}
}
开发者ID:Torqueware,项目名称:marantz,代码行数:17,代码来源:marantz.go


示例19: loadEndpointsConfig

func loadEndpointsConfig() {
	//Login
	Config.LoginURI = viper.GetString("stormpath.web.login.uri")
	Config.LoginNextURI = viper.GetString("stormpath.web.login.nextUri")
	Config.LoginView = viper.GetString("stormpath.web.login.view")
	Config.LoginEnabled = viper.GetBool("stormpath.web.login.enabled")
	//Register
	Config.RegisterURI = viper.GetString("stormpath.web.register.uri")
	Config.RegisterView = viper.GetString("stormpath.web.register.view")
	Config.RegisterNextURI = viper.GetString("stormpath.web.register.uri")
	Config.RegisterEnabled = viper.GetBool("stormpath.web.register.enabled")
	Config.RegisterAutoLoginEnabled = viper.GetBool("stormpath.web.register.autoLogin")
	//Verify
	Config.VerifyURI = viper.GetString("stormpath.web.verifyEmail.uri")
	Config.VerifyEnabled = loadBoolPtr("stormpath.web.verifyEmail.enabled")
	Config.VerifyView = viper.GetString("stormpath.web.verifyEmail.view")
	Config.VerifyNextURI = viper.GetString("stormpath.web.verifyEmail.nextUri")
	//Forgot Password
	Config.ForgotPasswordURI = viper.GetString("stormpath.web.forgotPassword.uri")
	Config.ForgotPasswordNextURI = viper.GetString("stormpath.web.forgotPassword.nextUri")
	Config.ForgotPasswordView = viper.GetString("stormpath.web.forgotPassword.view")
	Config.ForgotPasswordEnabled = loadBoolPtr("stormpath.web.forgotPassword.enabled")
	//Change Password
	Config.ChangePasswordURI = viper.GetString("stormpath.web.changePassword.uri")
	Config.ChangePasswordNextURI = viper.GetString("stormpath.web.changePassword.nextUri")
	Config.ChangePasswordView = viper.GetString("stormpath.web.changePassword.view")
	Config.ChangePasswordEnabled = loadBoolPtr("stormpath.web.changePassword.enabled")
	Config.ChangePasswordAutoLoginEnabled = viper.GetBool("stormpath.web.changePassword.autoLogin")
	Config.ChangePasswordErrorURI = viper.GetString("stormpath.web.changePassword.errorUri")
	//Logout
	Config.LogoutURI = viper.GetString("stormpath.web.logout.uri")
	Config.LogoutNextURI = viper.GetString("stormpath.web.logout.nextUri")
	Config.LogoutEnabled = viper.GetBool("stormpath.web.logout.enabled")
	//IDSite
	Config.IDSiteEnabled = viper.GetBool("stormpath.web.idSite.enabled")
	Config.IDSiteLoginURI = viper.GetString("stormpath.web.idSite.loginUri")
	Config.IDSiteForgotURI = viper.GetString("stormpath.web.idSite.forgotUri")
	Config.IDSiteRegisterURI = viper.GetString("stormpath.web.idSite.registerUri")
	Config.CallbackEnabled = viper.GetBool("stormpath.web.callback.enabled")
	Config.CallbackURI = viper.GetString("stormpath.web.callback.uri")
	//Me
	Config.MeEnabled = viper.GetBool("stormpath.web.me.enabled")
	Config.MeURI = viper.GetString("stormpath.web.me.uri")
	Config.MeExpand = viper.GetStringMap("stormpath.web.me.expand")
}
开发者ID:jxstanford,项目名称:stormpath-sdk-go,代码行数:45,代码来源:config.go


示例20: RenderSitemap

func (s *Site) RenderSitemap() error {
	if viper.GetBool("DisableSitemap") {
		return nil
	}

	sitemapDefault := parseSitemap(viper.GetStringMap("Sitemap"))

	n := s.NewNode()

	// Prepend homepage to the list of pages
	pages := make(Pages, 0)

	page := &Page{}
	page.Date = s.Info.LastChange
	page.Lastmod = 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
		}

		if page.Sitemap.Filename == "" {
			page.Sitemap.Filename = sitemapDefault.Filename
		}
	}

	smLayouts := []string{"sitemap.xml", "_default/sitemap.xml", "_internal/_default/sitemap.xml"}

	if err := s.renderAndWriteXML("sitemap", page.Sitemap.Filename, n, s.appendThemeTemplates(smLayouts)...); err != nil {
		return err
	}

	return nil
}
开发者ID:lismore,项目名称:hugo,代码行数:45,代码来源:site.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang viper.GetStringMapString函数代码示例发布时间:2022-05-28
下一篇:
Golang viper.GetString函数代码示例发布时间: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