First commit
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"gopkg.in/yaml.v2"
|
||||
"os"
|
||||
)
|
||||
|
||||
var root Config
|
||||
|
||||
type Config struct {
|
||||
Database Database `yaml:"database"`
|
||||
Users Users `yaml:"users"`
|
||||
Server Server `yaml:"server"`
|
||||
}
|
||||
|
||||
func Get() Config {
|
||||
return root
|
||||
}
|
||||
|
||||
func Load(path string) (Config, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
err = yaml.NewDecoder(f).Decode(&root)
|
||||
return root, err
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package config
|
||||
|
||||
type Database struct {
|
||||
Driver string `yaml:"driver"`
|
||||
Path string `yaml:"path"`
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package config
|
||||
|
||||
type Server struct {
|
||||
Listen string
|
||||
Debug bool
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package config
|
||||
|
||||
type Users struct {
|
||||
AllowRegister bool `yaml:"allow_register"`
|
||||
}
|
||||
Reference in New Issue
Block a user