2016-08-13 11:03:03 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2016-09-02 21:32:56 +02:00
|
|
|
"gopkg.in/yaml.v2"
|
2016-08-13 11:03:03 +02:00
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
2016-10-11 20:16:24 +02:00
|
|
|
// Data of readed configuration
|
|
|
|
var Data *Config
|
|
|
|
|
2016-08-13 11:03:03 +02:00
|
|
|
// Config is the struct of the api
|
|
|
|
type Config struct {
|
|
|
|
API struct {
|
2016-08-14 13:33:53 +02:00
|
|
|
Address string `yaml:"address"`
|
|
|
|
Port string `yaml:"port"`
|
|
|
|
AllowedOrigins string `yaml:"allowedorigins"`
|
2016-08-13 11:03:03 +02:00
|
|
|
} `yaml:"api"`
|
2016-08-14 15:29:54 +02:00
|
|
|
Log struct {
|
|
|
|
Path string `yaml:"path"`
|
|
|
|
} `yaml:"log"`
|
2016-09-01 22:19:39 +02:00
|
|
|
Webroot string `yaml:"webroot"`
|
|
|
|
Database string `yaml:"database"`
|
|
|
|
DatabaseDebug bool `yaml:"databasedebug"`
|
|
|
|
Modules map[string]*ModulConfig `yaml:"modules"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ModulConfig a spezific configuration for a modul
|
|
|
|
type ModulConfig struct {
|
|
|
|
Enabled bool `yaml:"enabled"`
|
|
|
|
Database string `yaml:"database,omitempty"`
|
2016-08-13 11:03:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReadConfigFile reads a config models by path to a yml file
|
2016-10-11 20:16:24 +02:00
|
|
|
func ReadConfigFile(path string) {
|
2016-08-13 11:03:03 +02:00
|
|
|
config := &Config{}
|
|
|
|
file, _ := ioutil.ReadFile(path)
|
|
|
|
err := yaml.Unmarshal(file, &config)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2016-10-11 20:16:24 +02:00
|
|
|
Data = config
|
2016-08-13 11:03:03 +02:00
|
|
|
}
|