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

Golang viper.GetStringMapString函数代码示例

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

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



在下文中一共展示了GetStringMapString函数的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"),
		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


示例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"),
		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


示例3: RenderTaxonomiesLists

// Render the listing pages based on the meta data
// each unique term within a taxonomy will have a page created
func (s *Site) RenderTaxonomiesLists() error {
	wg := &sync.WaitGroup{}

	taxes := make(chan taxRenderInfo)
	results := make(chan error)

	procs := getGoMaxProcs()

	for i := 0; i < procs*4; i++ {
		wg.Add(1)
		go taxonomyRenderer(s, taxes, results, wg)
	}

	errs := make(chan error)

	go errorCollator(results, errs)

	taxonomies := viper.GetStringMapString("Taxonomies")
	for singular, plural := range taxonomies {
		for key, pages := range s.Taxonomies[plural] {
			taxes <- taxRenderInfo{key, pages, singular, plural}
		}
	}
	close(taxes)

	wg.Wait()

	close(results)

	err := <-errs
	if err != nil {
		return fmt.Errorf("Error(s) rendering taxonomies: %s", err)
	}
	return nil
}
开发者ID:jaden,项目名称:hugo,代码行数:37,代码来源:site.go


示例4: main

func main() {
	viper.SetConfigName("config")
	viper.AddConfigPath(".")
	err := viper.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}

	urls := viper.GetStringMapString("urls")
	username := viper.GetString("auth.username")
	password := viper.GetString("auth.password")

	for title, url := range urls {
		c := Checker{
			Title:    title,
			URL:      url,
			Username: username,
			Password: password,
		}

		go func() {
			for {
				if err := c.Check(); err != nil {
					log.Println(err)
				}
				time.Sleep(time.Second * 5)
			}
		}()
	}

	select {}
}
开发者ID:stayradiated,项目名称:autowatch,代码行数:32,代码来源:main.go


示例5: fetchAttributes

func (aca *ACA) fetchAttributes(id, affiliation string) ([]*AttributePair, error) {
	// TODO this attributes should be readed from the outside world in place of configuration file.
	var attributes = make([]*AttributePair, 0)
	attrs := viper.GetStringMapString("aca.attributes")

	for _, flds := range attrs {
		vals := strings.Fields(flds)
		if len(vals) >= 1 {
			val := ""
			for _, eachVal := range vals {
				val = val + " " + eachVal
			}
			attributeVals := strings.Split(val, ";")
			if len(attributeVals) >= 6 {
				attrPair, err := NewAttributePair(attributeVals, nil)
				if err != nil {
					return nil, errors.New("Invalid attribute entry " + val + " " + err.Error())
				}
				if attrPair.GetID() != id || attrPair.GetAffiliation() != affiliation {
					continue
				}
				attributes = append(attributes, attrPair)
			} else {
				Error.Printf("Invalid attribute entry '%v'", vals[0])
			}
		}
	}

	fmt.Printf("%v %v", id, attributes)

	return attributes, nil
}
开发者ID:cotrone,项目名称:fabric,代码行数:32,代码来源:aca.go


示例6: populateAffiliationGroupsTable

// populateAffiliationGroupsTable populates affiliation groups table.
//
func (eca *ECA) populateAffiliationGroupsTable() {
	key := "eca.affiliations"
	affiliationGroups := viper.GetStringMapString(key)
	for name := range affiliationGroups {
		eca.populateAffiliationGroup(name, "", key, 1)
	}
}
开发者ID:C0rWin,项目名称:fabric,代码行数:9,代码来源:eca.go


示例7: GetStringMapString

func GetStringMapString(key, mkey string) (error, string) {
	m := viper.GetStringMapString(key)[mkey]
	if m != "" {
		return nil, m
	}
	return errors.New("can't found:" + key + "," + mkey), ""
}
开发者ID:yiqguo,项目名称:LogCollect,代码行数:7,代码来源:config.go


示例8: ConfigFromViper

// ConfigFromViper imports configuration from Viper
func ConfigFromViper() Config {
	return Config{
		AuthServers: viper.GetStringMapString("auth-servers"),
		KeyDir:      viper.GetString("key-dir"),
		UseTLS:      viper.GetBool("tls"),
	}
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:8,代码来源:config.go


示例9: NewECA

// NewECA sets up a new ECA.
//
func NewECA() *ECA {
	var cooked string

	eca := &ECA{NewCA("eca"), nil, nil, nil, nil, nil}

	raw, err := ioutil.ReadFile(RootPath + "/obc.key")
	if err != nil {
		rand := rand.Reader
		key := make([]byte, 32) // AES-256
		rand.Read(key)
		cooked = base64.StdEncoding.EncodeToString(key)

		err = ioutil.WriteFile(RootPath+"/obc.key", []byte(cooked), 0644)
		if err != nil {
			Panic.Panicln(err)
		}
	} else {
		cooked = string(raw)
	}

	eca.obcKey, err = base64.StdEncoding.DecodeString(cooked)
	if err != nil {
		Panic.Panicln(err)
	}

	users := viper.GetStringMapString("eca.users")
	for id, pw := range users {
		eca.newUser(id, pw)
	}

	return eca
}
开发者ID:masterDev1985,项目名称:obc-peer,代码行数:34,代码来源:eca.go


示例10: RenderListsOfTaxonomyTerms

// Render a page per taxonomy that lists the terms for that taxonomy
func (s *Site) RenderListsOfTaxonomyTerms() (err error) {
	taxonomies := viper.GetStringMapString("Taxonomies")
	for singular, plural := range taxonomies {
		n := s.NewNode()
		n.Title = strings.Title(plural)
		s.setUrls(n, plural)
		n.Data["Singular"] = singular
		n.Data["Plural"] = plural
		n.Data["Terms"] = s.Taxonomies[plural]
		// keep the following just for legacy reasons
		n.Data["OrderedIndex"] = n.Data["Terms"]
		n.Data["Index"] = n.Data["Terms"]
		layouts := []string{"taxonomy/" + singular + ".terms.html", "_default/terms.html", "indexes/indexes.html"}
		layouts = s.appendThemeTemplates(layouts)
		if s.layoutExists(layouts...) {
			b, err := s.renderPage("taxonomy terms for "+singular, n, layouts...)
			if err != nil {
				return err
			}
			if err := s.WriteDestPage(plural+"/index.html", b); err != nil {
				return err
			}
		}
	}

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


示例11: initDB

func initDB() {
	dbConfig := viper.GetStringMapString("database")
	dsn := []string{dbConfig["dbUser"], ":", dbConfig["dbPass"], "@tcp(", dbConfig["dbHost"], ":3306)/", dbConfig["dbName"], "?charset=utf8"}

	db, _ = sql.Open("mysql", strings.Join(dsn, ""))
	//errHandle(err)
}
开发者ID:SeleneSoftware,项目名称:HermesInventory,代码行数:7,代码来源:inventory.go


示例12: listAllScripts

func listAllScripts() {
	scripts := viper.GetStringMapString("scripts")
	log.Info("all avaliable scripts are listed below")
	for name := range scripts {
		fmt.Println(name)
	}
}
开发者ID:dyweb,项目名称:Ayi,代码行数:7,代码来源:run.go


示例13: populateAffiliationGroupsTable

func (eca *ECA) populateAffiliationGroupsTable() {
	// populate affiliation groups
	key := "eca.affiliation_groups"
	affiliation_groups := viper.GetStringMapString(key)
	for name, _ := range affiliation_groups {
		eca.populateAffiliationGroup(name, "", key)
	}
}
开发者ID:RicHernandez2,项目名称:fabric,代码行数:8,代码来源:eca.go


示例14: windHandler

func windHandler(w http.ResponseWriter, r *http.Request, db *data.Database) {
	t, _ := computeTime(r.FormValue("time"))

	var queries []map[string]string
	err := json.Unmarshal([]byte(r.FormValue("query")), &queries)
	if err != nil {
		jww.ERROR.Println(err)
		return
	}

	var result struct {
		Data  [][]float64
		Label []string
	}

	result.Data = make([][]float64, len(queries))
	result.Label = make([]string, len(queries))

	rxp := regexp.MustCompile(`\[([^]]*)\]`)
	for index, querymap := range queries {
		result.Label[index] = querymap["label"]
		result.Data[index] = make([]float64, 32)

		id := "%"
		if _, ok := querymap["id"]; ok {
			id = querymap["id"]
		}
		datatype := "%"
		if _, ok := querymap["type"]; ok {
			datatype = querymap["type"]
		}
		if _, ok := querymap["label"]; ok {
			result.Label[index] = querymap["label"]
		} else {
			result.Label[index] = "Unknown"
		}
		cols := rxp.FindStringSubmatch(datatype)
		var col string
		if len(cols) > 1 {
			col = cols[1]
		} else {
			col = "avg"
		}

		key := rxp.ReplaceAllString(datatype, "")

		for row := range db.QueryWind(t, key, col, id, 0) {
			speed := units.NewSpeedMetersPerSecond(row.Value)
			result.Data[index][int(row.Dir)], err = speed.Get(viper.GetStringMapString("units")["WindSpeed"])
			if err != nil {
				jww.ERROR.Println(err)
				return
			}
		}
	}

	json.NewEncoder(w).Encode(result)
}
开发者ID:geoffholden,项目名称:gowx,代码行数:58,代码来源:server.go


示例15: write_config

func write_config(c *cli.Context, files map[string]string) error {
	user := c.String("user")
	password := c.String("password")
	if len(user) == 0 || len(password) == 0 {
		cli.ShowSubcommandHelp(c)
		return nil
	}
	for n, b := range files {
		if err := os.MkdirAll(path.Dir(n), 0700); err != nil {
			return err
		}
		fmt.Printf("generate file %s\n", n)
		fd, err := os.OpenFile(
			n,
			os.O_WRONLY|os.O_CREATE|os.O_EXCL,
			0600)
		if err != nil {
			return err
		}
		defer fd.Close()
		t, err := template.New("").Parse(b)
		if err != nil {
			return err
		}
		driver := viper.GetString("database.driver")
		switch driver {
		case "postgres":
			driver = "pgsql"
		}
		args := viper.GetStringMapString("database.args")
		if err = t.Execute(fd, struct {
			Driver      string
			User        string
			Password    string
			Name        string
			Host        string
			Port        string
			UserTable   string
			AliasTable  string
			DomainTable string
		}{
			Driver:      driver,
			Host:        args["host"],
			Name:        args["dbname"],
			Port:        args["port"],
			Password:    password,
			User:        user,
			UserTable:   User{}.TableName(),
			AliasTable:  Alias{}.TableName(),
			DomainTable: Domain{}.TableName(),
		}); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:itpkg,项目名称:chaos,代码行数:57,代码来源:shell.go


示例16: populateAffiliationGroup

// populateAffiliationGroup populates the affiliation groups table.
//
func (eca *ECA) populateAffiliationGroup(name, parent, key string) {
	eca.registerAffiliationGroup(name, parent)
	newKey := key + "." + name
	affiliationGroups := viper.GetStringMapString(newKey)
	for childName := range affiliationGroups {
		eca.populateAffiliationGroup(childName, name, newKey)
	}

}
开发者ID:magooster,项目名称:obc-peer,代码行数:11,代码来源:eca.go


示例17: Stats

func (s *Site) Stats() {
	jww.FEEDBACK.Printf("%d pages created \n", len(s.Pages))

	indexes := viper.GetStringMapString("Indexes")

	for _, pl := range indexes {
		jww.FEEDBACK.Printf("%d %s index created\n", len(s.Indexes[pl]), pl)
	}
}
开发者ID:h0wn0w,项目名称:hugo,代码行数:9,代码来源:site.go


示例18: Stats

func (s *Site) Stats() {
	jww.FEEDBACK.Printf("%d pages created \n", len(s.Pages))

	taxonomies := viper.GetStringMapString("Taxonomies")

	for _, pl := range taxonomies {
		jww.FEEDBACK.Printf("%d %s created\n", len(s.Taxonomies[pl]), pl)
	}
}
开发者ID:NkS90,项目名称:hugo,代码行数:9,代码来源:site.go


示例19: BuildSiteMeta

func (s *Site) BuildSiteMeta() (err error) {
	s.Indexes = make(IndexList)
	s.Sections = make(Index)

	indexes := viper.GetStringMapString("Indexes")
	jww.INFO.Printf("found indexes: %#v\n", indexes)

	for _, plural := range indexes {
		s.Indexes[plural] = make(Index)
		for _, p := range s.Pages {
			vals := p.GetParam(plural)
			weight := p.GetParam(plural + "_weight")
			if weight == nil {
				weight = 0
			}

			if vals != nil {
				v, ok := vals.([]string)
				if ok {
					for _, idx := range v {
						x := WeightedPage{weight.(int), p}

						s.Indexes[plural].Add(idx, x)
					}
				} else {
					jww.ERROR.Printf("Invalid %s in %s\n", plural, p.File.FileName)
				}
			}
		}
		for k := range s.Indexes[plural] {
			s.Indexes[plural][k].Sort()
		}
	}

	for i, p := range s.Pages {
		s.Sections.Add(p.Section, WeightedPage{s.Pages[i].Weight, s.Pages[i]})
	}

	for k := range s.Sections {
		s.Sections[k].Sort()
	}

	s.Info.Indexes = s.Indexes

	if len(s.Pages) == 0 {
		return
	}
	s.Info.LastChange = s.Pages[0].Date

	// populate pages with site metadata
	for _, p := range s.Pages {
		p.Site = s.Info
	}

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


示例20: GetTestConfig

// GetTestConfig : Return test config based on package name
func GetTestConfig(packageName string) map[string]string {
	path, _ := filepath.Abs("../")
	viper.SetConfigName("test_config")
	viper.AddConfigPath(path)
	if err := viper.ReadInConfig(); err != nil {
		log.Fatalf("Error : %s", err)
	}

	return viper.GetStringMapString(packageName)
}
开发者ID:budhrg,项目名称:atlantis-manager,代码行数:11,代码来源:util.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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