本文整理汇总了Golang中github.com/magiconair/properties.Load函数的典型用法代码示例。如果您正苦于以下问题:Golang Load函数的具体用法?Golang Load怎么用?Golang Load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Load函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestStringVal
func TestStringVal(t *testing.T) {
props := func(s string) *properties.Properties {
p, err := properties.Load([]byte(s), properties.UTF8)
if err != nil {
t.Fatal(err)
}
return p
}
tests := []struct {
env map[string]string
props *properties.Properties
keys []string
val string
def string
}{
{
env: nil,
props: nil,
keys: []string{"key"}, val: "default", def: "default",
},
{
env: map[string]string{"key": "env"},
props: nil,
keys: []string{"key"}, val: "env",
},
{
env: nil,
props: props("key=props"),
keys: []string{"key"}, val: "props",
},
{
env: map[string]string{"key": "env"},
props: props("key=props"),
keys: []string{"key"}, val: "env",
},
{
env: map[string]string{"key": "env"},
props: props("other=props"),
keys: []string{"other"}, val: "props",
},
{
env: map[string]string{"key": "env"},
props: props("other=props"),
keys: []string{"key", "other"}, val: "env",
},
}
for i, tt := range tests {
for k, v := range tt.env {
os.Setenv(k, v)
}
if got, want := stringVal(tt.props, tt.def, tt.keys...), tt.val; got != want {
t.Errorf("%d: got %s want %s", i, got, want)
}
for k := range tt.env {
os.Unsetenv(k)
}
}
}
开发者ID:r0p0s3c,项目名称:fabio,代码行数:60,代码来源:load_test.go
示例2: 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
示例3: loadRemoteComponents
func loadRemoteComponents() *properties.Properties {
var configFile string
if runtime.GOOS == "windows" {
configFile = "win"
} else if runtime.GOOS == "linux" && ARCH_BITS == 32 {
configFile = "lnx-32"
} else if runtime.GOOS == "linux" && ARCH_BITS == 64 {
configFile = "lnx-64"
} else {
panic("Platform not supported")
}
body, err := fetchURLContent("http://install-versions.risevision.com/remote-components-" + configFile + ".cfg")
if err != nil {
fmt.Println("Error loading remote components file")
}
props, err := properties.Load(body, properties.UTF8)
if err != nil {
fmt.Println("Error reading remote components file")
}
return props
}
开发者ID:fjvallarino,项目名称:rise-launcher-test-go,代码行数:27,代码来源:main.go
示例4: Config
func Config() *properties.Properties {
if configProperties == nil {
cfg := defaultConfig
cfgPath, err := filepath.Abs(ConfigPath)
if err != nil {
panic(err)
}
if cfgFile, err := ioutil.ReadFile(cfgPath); os.IsNotExist(err) {
// pass
} else if err != nil {
panic(err)
} else {
cfg = append(cfg, cfgFile...)
}
if props, err := properties.Load(cfg, properties.UTF8); err != nil {
panic(err)
} else {
for k, v := range ConfigOverrides {
if _, _, err := props.Set(k, v); err != nil {
panic(err)
}
}
configPath = cfgPath
configProperties = props
}
}
return configProperties
}
开发者ID:saper,项目名称:jetpack,代码行数:30,代码来源:config.go
示例5: 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
示例6: 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
示例7: 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
示例8: 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
示例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":
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
示例10: TestFromProperties
func TestFromProperties(t *testing.T) {
in := `
proxy.addr = :1234
proxy.localip = 4.4.4.4
proxy.strategy = rr
proxy.shutdownwait = 500ms
proxy.timeout = 3s
proxy.dialtimeout = 60s
proxy.readtimeout = 5s
proxy.writetimeout = 10s
proxy.maxconn = 666
proxy.header.clientip = clientip
proxy.header.tls = tls
proxy.header.tls.value = tls-true
registry.backend = something
registry.file.path = /foo/bar
registry.static.routes = route add svc / http://127.0.0.1:6666/
registry.consul.addr = 1.2.3.4:5678
registry.consul.token = consul-token
registry.consul.kvpath = /some/path
registry.consul.tagprefix = p-
registry.consul.register.addr = 6.6.6.6:7777
registry.consul.register.name = fab
registry.consul.register.checkInterval = 5s
registry.consul.register.checkTimeout = 10s
metrics.target = graphite
metrics.prefix = someprefix
metrics.interval = 5s
metrics.graphite.addr = 5.6.7.8:9999
runtime.gogc = 666
runtime.gomaxprocs = 12
ui.addr = 7.8.9.0:1234
ui.color = fonzy
ui.title = fabfab
`
out := &Config{
Proxy: Proxy{
MaxConn: 666,
LocalIP: "4.4.4.4",
Strategy: "rr",
ShutdownWait: 500 * time.Millisecond,
DialTimeout: 60 * time.Second,
KeepAliveTimeout: 3 * time.Second,
ResponseHeaderTimeout: 3 * time.Second,
ClientIPHeader: "clientip",
TLSHeader: "tls",
TLSHeaderValue: "tls-true",
},
Registry: Registry{
Backend: "something",
File: File{
Path: "/foo/bar",
},
Static: Static{
Routes: "route add svc / http://127.0.0.1:6666/",
},
Consul: Consul{
Addr: "1.2.3.4:5678",
Token: "consul-token",
KVPath: "/some/path",
TagPrefix: "p-",
ServiceAddr: "6.6.6.6:7777",
ServiceName: "fab",
CheckInterval: 5 * time.Second,
CheckTimeout: 10 * time.Second,
},
},
Listen: []Listen{
{
Addr: ":1234",
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
},
},
Metrics: []Metrics{
{
Target: "graphite",
Prefix: "someprefix",
Interval: 5 * time.Second,
Addr: "5.6.7.8:9999",
},
},
Runtime: Runtime{
GOGC: 666,
GOMAXPROCS: 12,
},
UI: UI{
Addr: "7.8.9.0:1234",
Color: "fonzy",
Title: "fabfab",
},
}
p, err := properties.Load([]byte(in), properties.UTF8)
if err != nil {
t.Fatalf("got %v want nil", err)
}
cfg, err := fromProperties(p)
if err != nil {
//.........这里部分代码省略.........
开发者ID:r0p0s3c,项目名称:fabio,代码行数:101,代码来源:load_test.go
示例11: TestFromProperties
//.........这里部分代码省略.........
metrics.interval = 5s
metrics.graphite.addr = 5.6.7.8:9999
runtime.gogc = 666
runtime.gomaxprocs = 12
ui.addr = 7.8.9.0:1234
ui.color = fonzy
ui.title = fabfab
aws.apigw.cert.cn = furb
`
out := &Config{
ListenerValue: []string{":1234"},
CertSourcesValue: []map[string]string{{"cs": "name", "type": "path", "cert": "foo", "clientca": "bar", "refresh": "99s", "hdr": "a: b", "caupgcn": "furb"}},
CertSources: map[string]CertSource{
"name": CertSource{
Name: "name",
Type: "path",
CertPath: "foo",
ClientCAPath: "bar",
CAUpgradeCN: "furb",
Refresh: 99 * time.Second,
Header: http.Header{"A": []string{"b"}},
},
},
Proxy: Proxy{
MaxConn: 666,
LocalIP: "4.4.4.4",
Strategy: "rr",
Matcher: "prefix",
NoRouteStatus: 929,
ShutdownWait: 500 * time.Millisecond,
DialTimeout: 60 * time.Second,
ResponseHeaderTimeout: 3 * time.Second,
KeepAliveTimeout: 4 * time.Second,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
ClientIPHeader: "clientip",
TLSHeader: "tls",
TLSHeaderValue: "tls-true",
},
Registry: Registry{
Backend: "something",
File: File{
Path: "/foo/bar",
},
Static: Static{
Routes: "route add svc / http://127.0.0.1:6666/",
},
Consul: Consul{
Addr: "1.2.3.4:5678",
Scheme: "https",
Token: "consul-token",
KVPath: "/some/path",
TagPrefix: "p-",
Register: false,
ServiceAddr: "6.6.6.6:7777",
ServiceName: "fab",
ServiceTags: []string{"a", "b", "c"},
ServiceStatus: []string{"a", "b"},
CheckInterval: 5 * time.Second,
CheckTimeout: 10 * time.Second,
},
},
Listen: []Listen{
{
Addr: ":1234",
Scheme: "http",
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
},
},
Metrics: Metrics{
Target: "graphite",
Prefix: "someprefix",
Interval: 5 * time.Second,
GraphiteAddr: "5.6.7.8:9999",
},
Runtime: Runtime{
GOGC: 666,
GOMAXPROCS: 12,
},
UI: UI{
Addr: "7.8.9.0:1234",
Color: "fonzy",
Title: "fabfab",
},
}
p, err := properties.Load([]byte(in), properties.UTF8)
if err != nil {
t.Fatalf("got %v want nil", err)
}
cfg, err := load(p)
if err != nil {
t.Fatalf("got %v want nil", err)
}
got, want := cfg, out
verify.Values(t, "cfg", got, want)
}
开发者ID:yexiaoming20140413,项目名称:fabio,代码行数:101,代码来源:load_test.go
注:本文中的github.com/magiconair/properties.Load函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论