删除文件不存在的报错信息

This commit is contained in:
bjdgyc 2021-06-09 16:41:15 +08:00
parent cd8922237f
commit a616e42432
1 changed files with 8 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package base package base
import ( import (
"errors"
"fmt" "fmt"
"math/rand" "math/rand"
"os" "os"
@ -63,7 +64,13 @@ func init() {
viper.SetConfigFile(cfgFile) viper.SetConfigFile(cfgFile)
viper.AutomaticEnv() viper.AutomaticEnv()
err := viper.ReadInConfig() _, err := os.Stat(cfgFile)
if errors.Is(err, os.ErrNotExist) {
// 文件不存在,不做处理
return
}
err = viper.ReadInConfig()
if err != nil { if err != nil {
fmt.Println("Using config file:", err) fmt.Println("Using config file:", err)
} }