本文整理汇总了Golang中github.com/astaxie/beego/config.Configer类的典型用法代码示例。如果您正苦于以下问题:Golang Configer类的具体用法?Golang Configer怎么用?Golang Configer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Configer类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: setGlobalConfig
func setGlobalConfig(conf config.Configer) error {
//config globals
if appname := conf.String("appname"); appname != "" {
AppName = appname
} else if appname == "" {
return fmt.Errorf("AppName config value is null")
}
if usage := conf.String("usage"); usage != "" {
Usage = usage
} else if usage == "" {
return fmt.Errorf("Usage config value is null")
}
if version := conf.String("version"); version != "" {
Version = version
} else if version == "" {
return fmt.Errorf("Version config value is null")
}
if author := conf.String("author"); author != "" {
Author = author
} else if author == "" {
return fmt.Errorf("Author config value is null")
}
if email := conf.String("email"); email != "" {
Email = email
} else if email == "" {
return fmt.Errorf("Email config value is null")
}
return nil
}
开发者ID:pombredanne,项目名称:dockyard,代码行数:34,代码来源:setting.go
示例2: ParseDIYToMap
// ParseDIYToMap is used to convert the json object to map[string]string
func ParseDIYToMap(cf config.Configer, name string) (m map[string]string, err error) {
DIY, err := cf.DIY(name)
if err != nil {
return
}
itf, ok := DIY.(map[string]interface{})
if !ok {
err = errors.New("value is not map[string]interface{}")
return
}
m = make(map[string]string)
for k, v := range itf {
m[k] = v.(string)
}
return
}
开发者ID:coseyo,项目名称:beeconfig,代码行数:17,代码来源:config.go
示例3: assignSingleConfig
func assignSingleConfig(p interface{}, ac config.Configer) {
pt := reflect.TypeOf(p)
if pt.Kind() != reflect.Ptr {
return
}
pt = pt.Elem()
if pt.Kind() != reflect.Struct {
return
}
pv := reflect.ValueOf(p).Elem()
for i := 0; i < pt.NumField(); i++ {
pf := pv.Field(i)
if !pf.CanSet() {
continue
}
name := pt.Field(i).Name
switch pf.Kind() {
case reflect.String:
pf.SetString(ac.DefaultString(name, pf.String()))
case reflect.Int, reflect.Int64:
pf.SetInt(int64(ac.DefaultInt64(name, pf.Int())))
case reflect.Bool:
pf.SetBool(ac.DefaultBool(name, pf.Bool()))
case reflect.Struct:
default:
//do nothing here
}
}
}
开发者ID:chaws,项目名称:beego,代码行数:31,代码来源:config.go
示例4: ParseDIYToMaps
// ParseDIYToMap is used to convert the json object to map[string]map[string]string
func ParseDIYToMaps(cf config.Configer, name string) (m map[string]map[string]string, err error) {
DIY, err := cf.DIY(name)
if err != nil {
return
}
itf, ok := DIY.(map[string]interface{})
if !ok {
err = errors.New("value is not map[string]interface{}")
return
}
m = make(map[string]map[string]string)
for k, v := range itf {
mTmp := v.(map[string]interface{})
for k2, v2 := range mTmp {
if _, exist := m[k]; !exist {
m[k] = make(map[string]string)
}
m[k][k2] = v2.(string)
}
}
return
}
开发者ID:coseyo,项目名称:beeconfig,代码行数:24,代码来源:config.go
示例5: assignConfig
func assignConfig(ac config.Configer) error {
// set the run mode first
if envRunMode := os.Getenv("BEEGO_RUNMODE"); envRunMode != "" {
BConfig.RunMode = envRunMode
} else if runMode := ac.String("RunMode"); runMode != "" {
BConfig.RunMode = runMode
}
for _, i := range []interface{}{BConfig, &BConfig.Listen, &BConfig.WebConfig, &BConfig.Log, &BConfig.WebConfig.Session} {
assignSingleConfig(i, ac)
}
if sd := ac.String("StaticDir"); sd != "" {
BConfig.WebConfig.StaticDir = map[string]string{}
sds := strings.Fields(sd)
for _, v := range sds {
if url2fsmap := strings.SplitN(v, ":", 2); len(url2fsmap) == 2 {
BConfig.WebConfig.StaticDir["/"+strings.Trim(url2fsmap[0], "/")] = url2fsmap[1]
} else {
BConfig.WebConfig.StaticDir["/"+strings.Trim(url2fsmap[0], "/")] = url2fsmap[0]
}
}
}
if sgz := ac.String("StaticExtensionsToGzip"); sgz != "" {
extensions := strings.Split(sgz, ",")
fileExts := []string{}
for _, ext := range extensions {
ext = strings.TrimSpace(ext)
if ext == "" {
continue
}
if !strings.HasPrefix(ext, ".") {
ext = "." + ext
}
fileExts = append(fileExts, ext)
}
if len(fileExts) > 0 {
BConfig.WebConfig.StaticExtensionsToGzip = fileExts
}
}
if lo := ac.String("LogOutputs"); lo != "" {
los := strings.Split(lo, ";")
for _, v := range los {
if logType2Config := strings.SplitN(v, ",", 2); len(logType2Config) == 2 {
BConfig.Log.Outputs[logType2Config[0]] = logType2Config[1]
} else {
continue
}
}
}
//init log
logs.Reset()
for adaptor, config := range BConfig.Log.Outputs {
err := logs.SetLogger(adaptor, config)
if err != nil {
fmt.Fprintln(os.Stderr, fmt.Sprintf("%s with the config %q got err:%s", adaptor, config, err.Error()))
}
}
logs.SetLogFuncCall(BConfig.Log.FileLineNum)
return nil
}
开发者ID:chaws,项目名称:beego,代码行数:65,代码来源:config.go
示例6: setServerConfig
func setServerConfig(conf config.Configer) error {
//config runtime
if runmode := conf.String("runmode"); runmode != "" {
RunMode = runmode
} else if runmode == "" {
return fmt.Errorf("RunMode config value is null")
}
if listenmode := conf.String("listenmode"); listenmode != "" {
ListenMode = listenmode
} else if listenmode == "" {
return fmt.Errorf("ListenMode config value is null")
}
if httpscertfile := conf.String("httpscertfile"); httpscertfile != "" {
HTTPSCertFile = httpscertfile
} else if httpscertfile == "" {
return fmt.Errorf("HttpsCertFile config value is null")
}
if httpskeyfile := conf.String("httpskeyfile"); httpskeyfile != "" {
HTTPSKeyFile = httpskeyfile
} else if httpskeyfile == "" {
return fmt.Errorf("HttpsKeyFile config value is null")
}
if logpath := conf.String("log::filepath"); logpath != "" {
LogPath = logpath
} else if logpath == "" {
return fmt.Errorf("LogPath config value is null")
}
if loglevel := conf.String("log::level"); loglevel != "" {
LogLevel = loglevel
} else if loglevel == "" {
return fmt.Errorf("LogLevel config value is null")
}
if databasedriver := conf.String("database::driver"); databasedriver != "" {
DatabaseDriver = databasedriver
} else if databasedriver == "" {
return fmt.Errorf("Database Driver config value is null")
}
if databaseuri := conf.String("database::uri"); databaseuri != "" {
DatabaseURI = databaseuri
} else if databaseuri == "" {
return fmt.Errorf("Database URI config vaule is null")
}
// Deployment domain could be empty
if domains := conf.String("deployment::domains"); domains != "" {
Domains = domains
} else if domains == "" {
return fmt.Errorf("Deployment domains config vaule is null")
}
//TODO: Add a config option for provide Docker Registry V1.
//TODO: Link @middle/header/setRespHeaders, @handler/dockerv1/-functions.
if standalone := conf.String("dockerv1::standalone"); standalone != "" {
DockerStandalone = standalone
} else if standalone == "" {
return fmt.Errorf("DockerV1 standalone value is null")
}
if registry := conf.String("dockerv1::version"); registry != "" {
DockerRegistryVersion = registry
} else if registry == "" {
return fmt.Errorf("DockerV1 Registry Version value is null")
}
if storage := conf.String("dockerv1::storage"); storage != "" {
DockerV1Storage = storage
} else if storage == "" {
return fmt.Errorf("DockerV1 Storage value is null")
}
if distribution := conf.String("dockerv2::distribution"); distribution != "" {
DockerDistributionVersion = distribution
} else if distribution == "" {
return fmt.Errorf("DockerV2 Distribution Version value is null")
}
if storage := conf.String("dockerv2::storage"); storage != "" {
DockerV2Storage = storage
} else if storage == "" {
return fmt.Errorf("DockerV2 Storage value is null")
}
if storage := conf.String("appc::storage"); storage != "" {
AppcStorage = storage
} else if storage == "" {
return fmt.Errorf("Appc Storage value is null")
}
//config update service
if uskeymanager := conf.String("updateserver::keymanager"); uskeymanager != "" {
KeyManager = uskeymanager
} else if uskeymanager == "" {
return fmt.Errorf("Update Server Key manager config value is null")
//.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:dockyard,代码行数:101,代码来源:setting.go
注:本文中的github.com/astaxie/beego/config.Configer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论