本文整理汇总了Golang中github.com/spf13/viper.GetStringMapString函数的典型用法代码示例。如果您正苦于以下问题:Golang GetStringMapString函数的具体用法?Golang GetStringMapString怎么用?Golang GetStringMapString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetStringMapString函数的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"),
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,
}
}
示例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,
}
}
示例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
}
示例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 {}
}
示例5: 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)
}
示例6: 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
}
示例7: 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)
}
}
示例8: 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), ""
}
示例9: 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"),
}
}
示例10: 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
}
示例11: 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
}
示例12: listAllScripts
func listAllScripts() {
scripts := viper.GetStringMapString("scripts")
log.Info("all avaliable scripts are listed below")
for name := range scripts {
fmt.Println(name)
}
}
示例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)
}
}
示例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)
}
示例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
}