Add config
This commit is contained in:
parent
c3664ef3e0
commit
65322bc182
32
config/config.go
Normal file
32
config/config.go
Normal 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user