初始化项目文件
This commit is contained in:
11
api_file/config/config.dev.yaml
Normal file
11
api_file/config/config.dev.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
database:
|
||||
dsn: web:Song1875.@tcp(43.154.168.226:3306)/web_vue?charset=utf8mb4&parseTime=True&loc=Local
|
||||
prd: false
|
||||
|
||||
logs:
|
||||
log: logs
|
||||
nginx: logs/nginx
|
||||
|
||||
sys:
|
||||
jwt: False
|
||||
User: admin
|
31
api_file/config/config.go
Normal file
31
api_file/config/config.go
Normal file
@ -0,0 +1,31 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v3"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Config 公共参数
|
||||
var Config settings
|
||||
|
||||
// InitConfig 配置初始化
|
||||
func InitConfig(version string) error {
|
||||
var file []byte
|
||||
var err error
|
||||
if version == "dev" {
|
||||
file, err = os.ReadFile("./config/config.dev.yaml")
|
||||
} else {
|
||||
file, err = os.ReadFile("./config/config.prd.yaml")
|
||||
}
|
||||
if err != nil {
|
||||
logrus.Errorln("Error reading config file:", err)
|
||||
return err
|
||||
}
|
||||
err = yaml.Unmarshal(file, &Config)
|
||||
if err != nil {
|
||||
logrus.Errorln("Error parsing config file:", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
11
api_file/config/config.prd.yaml
Normal file
11
api_file/config/config.prd.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
database:
|
||||
dsn: web_prd:SongPrd1875.@tcp(43.154.168.226:3306)/web_prd?charset=utf8mb4&parseTime=True&loc=Local
|
||||
prd: true
|
||||
|
||||
logs:
|
||||
log: logs
|
||||
nginx: logs/nginx
|
||||
|
||||
sys:
|
||||
jwt: True
|
||||
User:
|
21
api_file/config/type.d.go
Normal file
21
api_file/config/type.d.go
Normal file
@ -0,0 +1,21 @@
|
||||
package config
|
||||
|
||||
type settings struct {
|
||||
Logs *logs `yaml:"logs"`
|
||||
Database *database `yaml:"database"`
|
||||
}
|
||||
|
||||
type logs struct {
|
||||
Nginx string `yaml:"nginx"`
|
||||
Log string `yaml:"log"`
|
||||
}
|
||||
|
||||
type database struct {
|
||||
Dsn string `yaml:"dsn"`
|
||||
Prd bool `yaml:"prd"`
|
||||
}
|
||||
|
||||
type sys struct {
|
||||
Jwt string `yaml:"jwt"`
|
||||
User string `yaml:"user"`
|
||||
}
|
Reference in New Issue
Block a user