diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..c10daa4 --- /dev/null +++ b/config/config.go @@ -0,0 +1,24 @@ +package config + +import ( + "fmt" + "gopkg.in/yaml.v3" + "os" + "toutoukan/model/config" +) + +var Conf config.Config + +func Goinit() error { + data, err := os.ReadFile("./config.yaml") + if err != nil { + _ = fmt.Errorf("读取配置文件失败: %v", err) + return err + } + err = yaml.Unmarshal(data, &Conf) + if err != nil { + _ = fmt.Errorf("解析配置文件失败: %v", err) + return err + } + return nil +} diff --git a/model/config/config.go b/model/config/config.go new file mode 100644 index 0000000..6c2e391 --- /dev/null +++ b/model/config/config.go @@ -0,0 +1,21 @@ +package config + +type Config struct { + Port int `yaml:"port"` + Database struct { + Username string `yaml:"username"` + Password string `yaml:"password"` + Host string `yaml:"host"` + Port int `yaml:"port"` + Params string `yaml:"params"` + } `yaml:"database"` + Redis struct { + Host string `yaml:"host"` + Port int `yaml:"port"` + Username string `yaml:"username"` + Password string `yaml:"password"` + } `yaml:"redis"` + Jwtsecret string `yaml:"jwtsecret"` + WxID string `yaml:"wxid"` + Wxsecret string `yaml:"wxsecret"` +}