This commit is contained in:
xing 2023-05-31 23:12:16 +08:00
parent ae6e496dd8
commit 23c9cc1596
2 changed files with 6 additions and 7 deletions

View File

@ -30,7 +30,7 @@ var address string
var intReg = regexp.MustCompile(`^\d`) var intReg = regexp.MustCompile(`^\d`)
func init() { func init() {
flag.StringVar(&confPath, "c", "config.yaml", "config file") flag.StringVar(&confPath, "c", "config.yaml", "config file support json,yaml or url")
flag.StringVar(&address, "p", "", "listen address and port") flag.StringVar(&address, "p", "", "listen address and port")
flag.Parse() flag.Parse()
if address == "" && os.Getenv("PORT") == "" { if address == "" && os.Getenv("PORT") == "" {

View File

@ -113,12 +113,11 @@ func InitConfig(conf string) error {
err = json.Unmarshal(file, &c) err = json.Unmarshal(file, &c)
default: default:
err = yaml.Unmarshal(file, &c) err = yaml.Unmarshal(file, &c)
if err != nil { if err == nil {
err = json.Unmarshal(file, &c) break
if err == nil { }
break err = json.Unmarshal(file, &c)
} if err == nil {
} else {
break break
} }
return errors.New("invalid suffix config file") return errors.New("invalid suffix config file")