Add config

This commit is contained in:
Jan Bader 2016-12-20 10:08:24 +01:00
parent c3664ef3e0
commit 65322bc182

32
config/config.go Normal file
View File

@ -0,0 +1,32 @@
package config
import (
"encoding/json"
"os"
)
// Config contains all needed configurations
type Config struct {
DatabaseUser string
DatabaseHost string
DatabasePassword string
DatabaseName string
file *os.File
}
// LoadConfig from path
func LoadConfig(path string) (*Config, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
decoder := json.NewDecoder(file)
configuration := Config{}
err = decoder.Decode(&configuration)
if err != nil {
return nil, err
}
return &configuration, nil
}