33 lines
586 B
Go
33 lines
586 B
Go
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
|
|
}
|