From b8a1d2ff572b585fd567f631ee58935ed3ffd122 Mon Sep 17 00:00:00 2001 From: mayiming <1627832236@qq.com> Date: Sun, 10 Aug 2025 02:10:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.go | 24 ++++++++++++++++++++++++ model/config/config.go | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 config/config.go create mode 100644 model/config/config.go 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"` +}