From 23c9cc1596e8b359180673ef0e7a26941ca34d84 Mon Sep 17 00:00:00 2001 From: xing Date: Wed, 31 May 2023 23:12:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/cmd/main.go | 2 +- app/pkg/config/config.go | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/cmd/main.go b/app/cmd/main.go index 57ae5ef..eb18a4b 100644 --- a/app/cmd/main.go +++ b/app/cmd/main.go @@ -30,7 +30,7 @@ var address string var intReg = regexp.MustCompile(`^\d`) 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.Parse() if address == "" && os.Getenv("PORT") == "" { diff --git a/app/pkg/config/config.go b/app/pkg/config/config.go index 7979d9a..c4fd23d 100644 --- a/app/pkg/config/config.go +++ b/app/pkg/config/config.go @@ -113,12 +113,11 @@ func InitConfig(conf string) error { err = json.Unmarshal(file, &c) default: err = yaml.Unmarshal(file, &c) - if err != nil { - err = json.Unmarshal(file, &c) - if err == nil { - break - } - } else { + if err == nil { + break + } + err = json.Unmarshal(file, &c) + if err == nil { break } return errors.New("invalid suffix config file")