grain/relay/utils/loadConfig.go

36 lines
548 B
Go
Raw Normal View History

package utils
import (
2024-07-20 02:08:27 +00:00
"os"
"gopkg.in/yaml.v2"
)
type Config struct {
MongoDB struct {
URI string `yaml:"uri"`
Database string `yaml:"database"`
} `yaml:"mongodb"`
2024-07-23 20:40:39 +00:00
Relay struct {
Port string `yaml:"port"`
} `yaml:"relay"`
Web struct {
Port string `yaml:"port"`
} `yaml:"web"`
}
func LoadConfig(filename string) (*Config, error) {
2024-07-20 02:08:27 +00:00
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
}