Skip to content

Commit

Permalink
Update common.go
Browse files Browse the repository at this point in the history
  • Loading branch information
xxjwxc committed Dec 21, 2020
1 parent 17dab2b commit db10851
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions data/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package config
import (
"fmt"
"io/ioutil"
"os"
"path"

"github.com/xxjwxc/public/mylog"

"github.com/xxjwxc/public/dev"
"github.com/xxjwxc/public/tools"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -47,7 +48,14 @@ var _map = Config{
var configPath string

func init() {
configPath = path.Join(tools.GetCurrentDirectory(), "config.yml")
configPath = path.Join(tools.GetCurrentDirectory(), "config.yml") // 先找本程序文件夹
if !tools.CheckFileIsExist(configPath) { // dont find it
configPath = path.Join(tools.GetModelPath(), "config.yml")
if !tools.CheckFileIsExist(configPath) {
mylog.ErrorString("config.yml not exit. using default config")
}
}

onInit()
dev.OnSetDev(_map.IsDev)
}
Expand All @@ -62,16 +70,16 @@ func onInit() {

// InitFile default value from file .
func InitFile(filename string) error {
if _, e := os.Stat(filename); e != nil {
fmt.Println("init default config file: ", filename)
if err := SaveToFile(); err == nil {
InitFile(filename)
return nil
} else {
fmt.Println("shit,fail", err)
}
// os.Exit(0)
}
// if _, e := os.Stat(filename); e != nil {
// fmt.Println("init default config file: ", filename)
// if err := SaveToFile(); err == nil {
// InitFile(filename)
// return nil
// } else {
// fmt.Println("shit,fail", err)
// }
// // os.Exit(0)
// }
bs, err := ioutil.ReadFile(filename)
if err != nil {
return err
Expand Down

0 comments on commit db10851

Please sign in to comment.