This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
2016-08-13 11:03:03 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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-08-14 13:33:53 +02:00
|
|
|
Webroot string `yaml:"webroot"`
|
|
|
|
Database string `yaml:"database"`
|
|
|
|
DatabaseDebug bool `yaml:"databasedebug"`
|
|
|
|
Modules []struct {
|
2016-08-13 11:03:03 +02:00
|
|
|
Name string `yaml:"name"`
|
|
|
|
Database string `yaml:"database"`
|
|
|
|
} `yaml:"modules"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadConfigFile reads a config models by path to a yml file
|
|
|
|
func ReadConfigFile(path string) *Config {
|
|
|
|
config := &Config{}
|
|
|
|
file, _ := ioutil.ReadFile(path)
|
|
|
|
err := yaml.Unmarshal(file, &config)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
return config
|
|
|
|
}
|