34 lines
653 B
Go
34 lines
653 B
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
"log"
|
||
|
|
||
|
"gopkg.in/yaml.v2"
|
||
|
)
|
||
|
|
||
|
// Config is the struct of the api
|
||
|
type Config struct {
|
||
|
API struct {
|
||
|
Address string `yaml:"address"`
|
||
|
Port string `yaml:"port"`
|
||
|
} `yaml:"api"`
|
||
|
Webroot string `yaml:"webroot"`
|
||
|
Database string `yaml:"database"`
|
||
|
Modules []struct {
|
||
|
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
|
||
|
}
|