mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-11-22 08:37:13 +00:00
37 lines
626 B
Go
37 lines
626 B
Go
package utils
|
|
|
|
import (
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
type Config struct {
|
|
MongoDB struct {
|
|
URI string `yaml:"uri"`
|
|
Database string `yaml:"database"`
|
|
} `yaml:"mongodb"`
|
|
Collections struct {
|
|
EventKind0 string `yaml:"event_kind0"`
|
|
EventKind1 string `yaml:"event_kind1"`
|
|
} `yaml:"collections"`
|
|
Server struct {
|
|
Address string `yaml:"address"`
|
|
} `yaml:"server"`
|
|
}
|
|
|
|
func LoadConfig(filename string) (*Config, error) {
|
|
data, err := os.ReadFile(filename)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var config Config
|
|
err = yaml.Unmarshal(data, &config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &config, nil
|
|
}
|