本文整理汇总了Golang中github.com/magiconair/properties.Properties类的典型用法代码示例。如果您正苦于以下问题:Golang Properties类的具体用法?Golang Properties怎么用?Golang Properties使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Properties类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: marshallConfigReader
func marshallConfigReader(in io.Reader, c map[string]interface{}, configType string) error {
buf := new(bytes.Buffer)
buf.ReadFrom(in)
switch strings.ToLower(configType) {
case "yaml", "yml":
if err := yaml.Unmarshal(buf.Bytes(), &c); err != nil {
return ConfigParseError{err}
}
case "json":
if err := json.Unmarshal(buf.Bytes(), &c); err != nil {
return ConfigParseError{err}
}
case "toml":
if _, err := toml.Decode(buf.String(), &c); err != nil {
return ConfigParseError{err}
}
case "properties", "props", "prop":
var p *properties.Properties
var err error
if p, err = properties.Load(buf.Bytes(), properties.UTF8); err != nil {
return ConfigParseError{err}
}
for _, key := range p.Keys() {
value, _ := p.Get(key)
c[key] = value
}
}
insensitiviseMap(c)
return nil
}
开发者ID:ARodri,项目名称:hume,代码行数:35,代码来源:util.go
示例2: FromProperties
func FromProperties(p *properties.Properties) (*Config, error) {
var cfg *Config = &Config{}
cfg.Listen.Port = p.GetString("receiver.addr", DefaultConfig.Listen.Port)
return cfg, nil
}
开发者ID:jamesrwu,项目名称:ammonitrix,代码行数:7,代码来源:load.go
示例3: marshallConfigReader
func marshallConfigReader(in io.Reader, c map[string]interface{}, configType string) {
buf := new(bytes.Buffer)
buf.ReadFrom(in)
switch configType {
case "yaml", "yml":
if err := yaml.Unmarshal(buf.Bytes(), &c); err != nil {
jww.ERROR.Fatalf("Error parsing config: %s", err)
}
case "json":
if err := json.Unmarshal(buf.Bytes(), &c); err != nil {
jww.ERROR.Fatalf("Error parsing config: %s", err)
}
case "toml":
if _, err := toml.Decode(buf.String(), &c); err != nil {
jww.ERROR.Fatalf("Error parsing config: %s", err)
}
case "properties", "props", "prop":
var p *properties.Properties
var err error
if p, err = properties.Load(buf.Bytes(), properties.UTF8); err != nil {
jww.ERROR.Fatalf("Error parsing config: %s", err)
}
for _, key := range p.Keys() {
value, _ := p.Get(key)
c[key] = value
}
}
insensitiviseMap(c)
}
开发者ID:nickwales,项目名称:proxym,代码行数:34,代码来源:util.go
示例4: unmarshallConfigReader
func unmarshallConfigReader(in io.Reader, c map[string]interface{}, configType string) error {
buf := new(bytes.Buffer)
buf.ReadFrom(in)
switch strings.ToLower(configType) {
case "yaml", "yml":
if err := yaml.Unmarshal(buf.Bytes(), &c); err != nil {
return ConfigParseError{err}
}
case "json":
if err := json.Unmarshal(buf.Bytes(), &c); err != nil {
return ConfigParseError{err}
}
case "hcl":
obj, err := hcl.Parse(string(buf.Bytes()))
if err != nil {
return ConfigParseError{err}
}
if err = hcl.DecodeObject(&c, obj); err != nil {
return ConfigParseError{err}
}
case "toml":
tree, err := toml.LoadReader(buf)
if err != nil {
return ConfigParseError{err}
}
tmap := tree.ToMap()
for k, v := range tmap {
c[k] = v
}
case "properties", "props", "prop":
var p *properties.Properties
var err error
if p, err = properties.Load(buf.Bytes(), properties.UTF8); err != nil {
return ConfigParseError{err}
}
for _, key := range p.Keys() {
value, _ := p.Get(key)
// recursively build nested maps
path := strings.Split(key, ".")
lastKey := strings.ToLower(path[len(path)-1])
deepestMap := deepSearch(c, path[0:len(path)-1])
// set innermost value
deepestMap[lastKey] = value
}
}
insensitiviseMap(c)
return nil
}
开发者ID:ovh,项目名称:tatcli,代码行数:54,代码来源:util.go
示例5: SetConfig
// Set's session manager configuration.
func (s *SessionManager) SetConfig(props *properties.Properties) {
for _, k := range props.Keys() {
parts := strings.Split(k, ".")
alias := parts[1]
config := s.configMap[alias]
if config == nil {
config = properties.NewProperties()
config.Set("alias", alias)
s.configMap[alias] = config
}
config.Set(parts[2], props.MustGet(k))
}
}
开发者ID:chai2010-playground,项目名称:mora,代码行数:14,代码来源:session.go
示例6: Parse
func (propertiesParser *PropertiesParser) Parse(content []byte, c map[string]interface{}) error {
var p *properties.Properties
p, err := properties.Load(content, properties.UTF8)
if err != nil {
return err
}
for _, key := range p.Keys() {
value, _ := p.Get(key)
c[key] = value
}
return err
}
开发者ID:zeroturnaround,项目名称:configo,代码行数:13,代码来源:properties.go
示例7: stringVal
// stringVal returns the first non-empty value found or the default value.
// Keys are checked in order and environment variables take precedence over
// properties values. Environment varaible names are derived from property
// names by replacing the dots with underscores.
func stringVal(p *properties.Properties, def string, keys ...string) string {
for _, key := range keys {
if v := os.Getenv(strings.Replace(key, ".", "_", -1)); v != "" {
return v
}
if p == nil {
continue
}
if v, ok := p.Get(key); ok {
return v
}
}
return def
}
开发者ID:emicklei,项目名称:fabio,代码行数:18,代码来源:load.go
示例8: ParseFlags
// ParseFlags parses command line arguments and provides fallback
// values from environment variables and config file values.
// Environment variables are case-insensitive and can have either
// of the provided prefixes.
func (f *FlagSet) ParseFlags(args, environ, prefixes []string, p *properties.Properties) error {
if err := f.Parse(args); err != nil {
return err
}
if len(prefixes) == 0 {
prefixes = []string{""}
}
// parse environment in case-insensitive way
env := map[string]string{}
for _, e := range environ {
p := strings.SplitN(e, "=", 2)
env[strings.ToUpper(p[0])] = p[1]
}
// determine all values that were set via cmdline
f.Visit(func(fl *flag.Flag) {
f.set[fl.Name] = true
})
// lookup the rest via environ and properties
f.VisitAll(func(fl *flag.Flag) {
// skip if already set
if f.set[fl.Name] {
return
}
// check environment variables
for _, pfx := range prefixes {
name := strings.ToUpper(pfx + strings.Replace(fl.Name, ".", "_", -1))
if val, ok := env[name]; ok {
f.set[fl.Name] = true
f.Set(fl.Name, val)
return
}
}
// check properties
if p == nil {
return
}
if val, ok := p.Get(fl.Name); ok {
f.set[fl.Name] = true
f.Set(fl.Name, val)
return
}
})
return nil
}
开发者ID:eBay,项目名称:fabio,代码行数:54,代码来源:flagset.go
示例9: unmarshallConfigReader
func unmarshallConfigReader(in io.Reader, c map[string]interface{}, configType string) error {
buf := new(bytes.Buffer)
buf.ReadFrom(in)
switch strings.ToLower(configType) {
case "yaml", "yml":
if err := yaml.Unmarshal(buf.Bytes(), &c); err != nil {
return ConfigParseError{err}
}
case "json":
if err := json.Unmarshal(buf.Bytes(), &c); err != nil {
return ConfigParseError{err}
}
case "hcl":
obj, err := hcl.Parse(string(buf.Bytes()))
if err != nil {
return ConfigParseError{err}
}
if err = hcl.DecodeObject(&c, obj); err != nil {
return ConfigParseError{err}
}
case "toml":
tree, err := toml.LoadReader(buf)
if err != nil {
return ConfigParseError{err}
}
tmap := tree.ToMap()
for k, v := range tmap {
c[k] = v
}
case "properties", "props", "prop":
var p *properties.Properties
var err error
if p, err = properties.Load(buf.Bytes(), properties.UTF8); err != nil {
return ConfigParseError{err}
}
for _, key := range p.Keys() {
value, _ := p.Get(key)
c[key] = value
}
}
insensitiviseMap(c)
return nil
}
开发者ID:jbeda,项目名称:kubernetes,代码行数:49,代码来源:util.go
示例10: downloadComponent
func downloadComponent(name string, config *properties.Properties) error {
out, err := os.Create(getTempFileName(name, config))
defer out.Close()
resp, err := http.Get(config.MustGetString(name))
defer resp.Body.Close()
if err != nil {
log.Fatal(err)
return err
}
_, err = io.Copy(out, resp.Body)
return err
}
开发者ID:fjvallarino,项目名称:rise-launcher-test-go,代码行数:16,代码来源:main.go
示例11: unmarshallConfigReader
func unmarshallConfigReader(in io.Reader, c map[string]interface{}, configType string) error {
buf := new(bytes.Buffer)
buf.ReadFrom(in)
switch strings.ToLower(configType) {
case "yaml", "yml":
if err := yaml.Unmarshal(buf.Bytes(), &c); err != nil {
return ConfigParseError{err}
}
case "json":
if err := json.Unmarshal(buf.Bytes(), &c); err != nil {
return ConfigParseError{err}
}
case "hcl":
obj, err := hcl.Parse(string(buf.Bytes()))
if err != nil {
return ConfigParseError{err}
}
if err = hcl.DecodeObject(&c, obj); err != nil {
return ConfigParseError{err}
}
case "toml":
if _, err := toml.Decode(buf.String(), &c); err != nil {
return ConfigParseError{err}
}
case "properties", "props", "prop":
var p *properties.Properties
var err error
if p, err = properties.Load(buf.Bytes(), properties.UTF8); err != nil {
return ConfigParseError{err}
}
if err = p.Decode(&c); err != nil {
return ConfigParseError{err}
}
}
insensitiviseMap(c)
return nil
}
开发者ID:doublerebel,项目名称:viper,代码行数:43,代码来源:util.go
示例12: buildURI
//"mongodb://linker:[email protected]:27017,172.17.2.44:27017/linker"
func buildURI(config *properties.Properties) string {
uri := config.GetString("uri", "")
if len(uri) <= 0 {
return uri
}
var commandTextBuffer bytes.Buffer
username := config.GetString("username", "")
password := config.GetString("password", "")
// port := config.GetString("port", "27017")
database := config.GetString("database", "")
prefix := "mongodb://"
commandTextBuffer.WriteString(prefix)
commandTextBuffer.WriteString(username + ":")
commandTextBuffer.WriteString(password + "@")
rs := []rune(uri)
ipPart := string(rs[len(prefix):len(uri)])
ips := strings.Split(ipPart, ",")
lenth := len(ips)
for i := 0; i < lenth-1; i++ {
ip := ips[i] + ","
commandTextBuffer.WriteString(ip)
}
lastIP := ips[lenth-1] + "/" + database
commandTextBuffer.WriteString(lastIP)
return commandTextBuffer.String()
}
开发者ID:popsuper1982,项目名称:DCOS_Cluster,代码行数:31,代码来源:session.go
示例13: getTempFileName
func getTempFileName(name string, config *properties.Properties) string {
return path.Join(os.TempDir(), path.Base(config.MustGetString(name)))
}
开发者ID:fjvallarino,项目名称:rise-launcher-test-go,代码行数:3,代码来源:main.go
示例14: fromProperties
func fromProperties(p *properties.Properties) (cfg *Config, err error) {
cfg = &Config{}
deprecate := func(key, msg string) {
_, exists := p.Get(key)
if exists {
log.Print("[WARN] config: ", msg)
}
}
cfg.Proxy = Proxy{
MaxConn: intVal(p, Default.Proxy.MaxConn, "proxy.maxconn"),
Strategy: stringVal(p, Default.Proxy.Strategy, "proxy.strategy"),
ShutdownWait: durationVal(p, Default.Proxy.ShutdownWait, "proxy.shutdownwait"),
DialTimeout: durationVal(p, Default.Proxy.DialTimeout, "proxy.dialtimeout"),
ResponseHeaderTimeout: durationVal(p, Default.Proxy.ResponseHeaderTimeout, "proxy.timeout"),
KeepAliveTimeout: durationVal(p, Default.Proxy.KeepAliveTimeout, "proxy.timeout"),
LocalIP: stringVal(p, Default.Proxy.LocalIP, "proxy.localip"),
ClientIPHeader: stringVal(p, Default.Proxy.ClientIPHeader, "proxy.header.clientip"),
TLSHeader: stringVal(p, Default.Proxy.TLSHeader, "proxy.header.tls"),
TLSHeaderValue: stringVal(p, Default.Proxy.TLSHeaderValue, "proxy.header.tls.value"),
}
readTimeout := durationVal(p, time.Duration(0), "proxy.readtimeout")
writeTimeout := durationVal(p, time.Duration(0), "proxy.writetimeout")
cfg.Listen, err = parseListen(stringVal(p, Default.Listen[0].Addr, "proxy.addr"), readTimeout, writeTimeout)
if err != nil {
return nil, err
}
cfg.Metrics = parseMetrics(
stringVal(p, Default.Metrics[0].Target, "metrics.target"),
stringVal(p, Default.Metrics[0].Prefix, "metrics.prefix"),
stringVal(p, Default.Metrics[0].Addr, "metrics.graphite.addr"),
durationVal(p, Default.Metrics[0].Interval, "metrics.interval"),
)
cfg.Registry = Registry{
Backend: stringVal(p, Default.Registry.Backend, "registry.backend"),
File: File{
Path: stringVal(p, Default.Registry.File.Path, "registry.file.path"),
},
Static: Static{
Routes: stringVal(p, Default.Registry.Static.Routes, "registry.static.routes"),
},
Consul: Consul{
Addr: stringVal(p, Default.Registry.Consul.Addr, "registry.consul.addr", "consul.addr"),
Token: stringVal(p, Default.Registry.Consul.Token, "registry.consul.token", "consul.token"),
KVPath: stringVal(p, Default.Registry.Consul.KVPath, "registry.consul.kvpath", "consul.kvpath"),
TagPrefix: stringVal(p, Default.Registry.Consul.TagPrefix, "registry.consul.tagprefix", "consul.tagprefix"),
ServiceAddr: stringVal(p, Default.Registry.Consul.ServiceAddr, "registry.consul.register.addr"),
ServiceName: stringVal(p, Default.Registry.Consul.ServiceName, "registry.consul.register.name", "consul.register.name"),
CheckInterval: durationVal(p, Default.Registry.Consul.CheckInterval, "registry.consul.register.checkInterval", "consul.register.checkInterval"),
CheckTimeout: durationVal(p, Default.Registry.Consul.CheckTimeout, "registry.consul.register.checkTimeout", "consul.register.checkTimeout"),
},
GoogleCloudPlatform: GoogleCloudPlatform{
CheckInterval: durationVal(p, Default.Registry.GoogleCloudPlatform.CheckInterval, "registry.gcp.updateEvery"),
Project: stringVal(p, Default.Registry.GoogleCloudPlatform.Project, "registry.gcp.project"),
Zone: stringVal(p, Default.Registry.GoogleCloudPlatform.Zone, "registry.gcp.zone"),
},
}
deprecate("consul.addr", "consul.addr has been replaced by registry.consul.addr")
deprecate("consul.token", "consul.token has been replaced by registry.consul.token")
deprecate("consul.kvpath", "consul.kvpath has been replaced by registry.consul.kvpath")
deprecate("consul.tagprefix", "consul.tagprefix has been replaced by registry.consul.tagprefix")
deprecate("consul.register.name", "consul.register.name has been replaced by registry.consul.register.name")
deprecate("consul.register.checkInterval", "consul.register.checkInterval has been replaced by registry.consul.register.checkInterval")
deprecate("consul.register.checkTimeout", "consul.register.checkTimeout has been replaced by registry.consul.register.checkTimeout")
deprecate("consul.url", "consul.url is obsolete. Please remove it.")
proxyRoutes := stringVal(p, "", "proxy.routes")
if strings.HasPrefix(proxyRoutes, "@") {
cfg.Registry.Backend = "file"
cfg.Registry.File.Path = proxyRoutes[1:]
deprecate("proxy.routes", "Please use registry.backend=file and registry.file.path=<path> instead of [email protected]<path>")
} else if proxyRoutes != "" {
cfg.Registry.Backend = "static"
cfg.Registry.Static.Routes = proxyRoutes
deprecate("proxy.routes", "Please use registry.backend=static and registry.static.routes=<routes> instead of proxy.routes=<routes>")
}
cfg.Runtime = Runtime{
GOGC: intVal(p, Default.Runtime.GOGC, "runtime.gogc"),
GOMAXPROCS: intVal(p, Default.Runtime.GOMAXPROCS, "runtime.gomaxprocs"),
}
if cfg.Runtime.GOMAXPROCS == -1 {
cfg.Runtime.GOMAXPROCS = runtime.NumCPU()
}
cfg.UI = UI{
Addr: stringVal(p, Default.UI.Addr, "ui.addr"),
Color: stringVal(p, Default.UI.Color, "ui.color"),
Title: stringVal(p, Default.UI.Title, "ui.title"),
}
dump(cfg)
return cfg, nil
}
开发者ID:emicklei,项目名称:fabio,代码行数:99,代码来源:load.go
注:本文中的github.com/magiconair/properties.Properties类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论