From 66409d93665b358daeae8a456fe7cb445e203187 Mon Sep 17 00:00:00 2001 From: chennqqi Date: Thu, 5 Nov 2020 11:52:55 +0800 Subject: [PATCH] fix: consul load config error not returned --- consul.v2/app.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/consul.v2/app.go b/consul.v2/app.go index c4b6dff..a8bd9f7 100644 --- a/consul.v2/app.go +++ b/consul.v2/app.go @@ -46,7 +46,7 @@ func ReadTxt(c *ConsulOperator, file string) ([]byte, error) { // ${appname}.yml, config/${appname} will be tried to load in order func NewConsulAppWithCfg(cfg interface{}, consulUrl string) (*ConsulApp, error) { var capp ConsulApp - + if consulUrl == "" { consulUrl = "127.0.0.1:8500" } @@ -108,7 +108,10 @@ func NewConsulAppWithCfg(cfg interface{}, consulUrl string) (*ConsulApp, error) txt, err := consulapi.Get(names[i]) if err == nil { log.Printf("[consul/app.go] successfully get consul kv: %v", names[i]) - yaml.Unmarshal(txt, cfg) + err = yaml.Unmarshal(txt, cfg) + if err != nil { + return &capp, err + } exist = true break } else {