123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package config
- import (
- "fmt"
- "io/ioutil"
- "os"
- "youngee_b_api/db"
- "youngee_b_api/model/system_model"
- "youngee_b_api/redis"
- "youngee_b_api/service"
- "gopkg.in/yaml.v2"
- )
- func Init() *system_model.Server {
- config := new(system_model.Config)
- env := getEnv()
- configPath := fmt.Sprintf("./config/%s.yaml", env)
- file, err := ioutil.ReadFile(configPath)
- if err != nil {
- panic(err)
- }
- //yaml文件内容影射到结构体中
- err = yaml.Unmarshal(file, config)
- if err != nil {
- panic(err)
- }
- loadExternelConfig(config)
- return config.Server
- }
- func loadExternelConfig(config *system_model.Config) {
- db.Init(config.Mysql)
- redis.Init(config.Redis)
- service.LoginAuthInit(config.Server.Session)
- }
- func getEnv() string {
- env := os.Getenv("youngee_env")
- if env == "" {
- env = "dev"
- }
- return env
- }
|