Exemple #1
0
func FromProperties(p *properties.Properties) (*Config, error) {
	var cfg *Config = &Config{}

	cfg.Listen.Port = p.GetString("receiver.addr", DefaultConfig.Listen.Port)

	return cfg, nil
}
Exemple #2
0
//"mongodb://*****:*****@localhost: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()
}