biblio/conf/configuration.go

29 lines
553 B
Go
Raw Permalink Normal View History

2022-10-04 21:09:31 +08:00
package conf
import (
"errors"
"os"
"gopkg.in/yaml.v2"
)
type Configuration struct {
ApiVersion string `json:"apiVersion" yaml:"apiVersion"`
Port int `json:"port" yaml:"port"`
MySQL MySQL `json:"mysql" yaml:"mysql"`
Redis Redis `json:"redis" yaml:"redis"`
}
func NewConfiguration(file string)(*Configuration, error){
if file == "" {
return nil ,errors.New("file not exist")
}
data, err := os.ReadFile(file)
if err != nil {
return nil, err
}
c := &Configuration{}
err = yaml.Unmarshal(data, c)
return c, err
}