Exemplo n.º 1
0
// Reads a ServerConfig from a JSON file.
func ReadConfig(path string) (*ServerConfig, error) {
	file, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer file.Close()

	data, err := ioutil.ReadAll(file)
	if err != nil {
		return nil, err
	}
	data = base.ConvertBackQuotedStrings(data)
	var config *ServerConfig
	if err := json.Unmarshal(data, &config); err != nil {
		return nil, err
	}

	// Validation:
	for name, dbConfig := range config.Databases {
		dbConfig.name = name
		if dbConfig.Bucket == nil {
			dbConfig.Bucket = &dbConfig.name
		}
		if dbConfig.Server == nil {
			dbConfig.Server = &DefaultServer
		}
		if dbConfig.Pool == nil {
			dbConfig.Pool = &DefaultPool
		}
	}
	return config, nil
}
Exemplo n.º 2
0
// Reads a ServerConfig from raw data
func ReadServerConfigFromData(data []byte) (*ServerConfig, error) {

	data = base.ConvertBackQuotedStrings(data)
	var config *ServerConfig
	if err := json.Unmarshal(data, &config); err != nil {
		return nil, err
	}

	// Validation:
	for name, dbConfig := range config.Databases {
		dbConfig.setup(name)
	}
	return config, nil
}
Exemplo n.º 3
0
// Reads a ServerConfig from a JSON file.
func ReadServerConfig(path string) (*ServerConfig, error) {
	file, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer file.Close()

	data, err := ioutil.ReadAll(file)
	if err != nil {
		return nil, err
	}
	data = base.ConvertBackQuotedStrings(data)
	var config *ServerConfig
	if err := json.Unmarshal(data, &config); err != nil {
		return nil, err
	}

	// Validation:
	for name, dbConfig := range config.Databases {
		dbConfig.setup(name)
	}
	return config, nil
}