44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package config
|
|
|
|
import (
|
|
"gopkg.in/yaml.v2"
|
|
"io/ioutil"
|
|
"log"
|
|
)
|
|
|
|
// Data of readed configuration
|
|
var Data *Config
|
|
|
|
// Config is the struct of the api
|
|
type Config struct {
|
|
API struct {
|
|
Address string `yaml:"address"`
|
|
Port string `yaml:"port"`
|
|
AllowedOrigins string `yaml:"allowedorigins"`
|
|
} `yaml:"api"`
|
|
Log struct {
|
|
Path string `yaml:"path"`
|
|
} `yaml:"log"`
|
|
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"`
|
|
}
|
|
|
|
// ReadConfigFile reads a config models by path to a yml file
|
|
func ReadConfigFile(path string) {
|
|
config := &Config{}
|
|
file, _ := ioutil.ReadFile(path)
|
|
err := yaml.Unmarshal(file, &config)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
Data = config
|
|
}
|