Update common.go
This commit is contained in:
@@ -3,9 +3,10 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
"github.com/xxjwxc/public/mylog"
|
||||||
|
|
||||||
"github.com/xxjwxc/public/dev"
|
"github.com/xxjwxc/public/dev"
|
||||||
"github.com/xxjwxc/public/tools"
|
"github.com/xxjwxc/public/tools"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@@ -47,7 +48,14 @@ var _map = Config{
|
|||||||
var configPath string
|
var configPath string
|
||||||
|
|
||||||
func init() {
|
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()
|
onInit()
|
||||||
dev.OnSetDev(_map.IsDev)
|
dev.OnSetDev(_map.IsDev)
|
||||||
}
|
}
|
||||||
@@ -62,16 +70,16 @@ func onInit() {
|
|||||||
|
|
||||||
// InitFile default value from file .
|
// InitFile default value from file .
|
||||||
func InitFile(filename string) error {
|
func InitFile(filename string) error {
|
||||||
if _, e := os.Stat(filename); e != nil {
|
// if _, e := os.Stat(filename); e != nil {
|
||||||
fmt.Println("init default config file: ", filename)
|
// fmt.Println("init default config file: ", filename)
|
||||||
if err := SaveToFile(); err == nil {
|
// if err := SaveToFile(); err == nil {
|
||||||
InitFile(filename)
|
// InitFile(filename)
|
||||||
return nil
|
// return nil
|
||||||
} else {
|
// } else {
|
||||||
fmt.Println("shit,fail", err)
|
// fmt.Println("shit,fail", err)
|
||||||
}
|
// }
|
||||||
// os.Exit(0)
|
// // os.Exit(0)
|
||||||
}
|
// }
|
||||||
bs, err := ioutil.ReadFile(filename)
|
bs, err := ioutil.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user