diff --git a/configs/configs.go b/configs/configs.go new file mode 100644 index 0000000..ec94a77 --- /dev/null +++ b/configs/configs.go @@ -0,0 +1,36 @@ +package configs + +import ( + "gopkg.in/yaml.v3" + "log" + "os" +) + +type Configs struct { +} + +// Settings 定义配置结构体 +var Settings Configs + +func readYamlFile(configFilePath string) (yamlFile []byte, err error) { + // 读取YAML文件 + if yamlFile, err = os.ReadFile(configFilePath); err != nil { + return nil, err + } + return yamlFile, err +} + +func NewConfig(configFilePath string) { + var ( + yamlFile []byte + err error + ) + // 读取配置文件 + if yamlFile, err = readYamlFile(configFilePath); err != nil { + log.Panic("读取配置文件失败: ", err) + } + // 解析YAML数据到配置结构体 + if err = yaml.Unmarshal(yamlFile, &Settings); err != nil { + log.Panic("解析配置文件失败: ", err) + } +} diff --git a/go.mod b/go.mod index 5d5c603..81b8fb6 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module picgo go 1.22 -require github.com/gorilla/mux v1.8.1 +require gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 7128337..4bc0337 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,3 @@ -github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= -github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=