當前位置: 首頁>>代碼示例>>Golang>>正文


Golang properties.Properties類代碼示例

本文整理匯總了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;未經允許,請勿轉載。