From 8546140e22d9ddbf554b8d4553e52476bc445d12 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 21 Jan 2022 19:13:21 +0300 Subject: [PATCH] errors: fix parsing Signed-off-by: Vasiliy Tolstov --- errors/errors.go | 14 +++++++------- go.mod | 2 +- go.sum | 4 ++-- logger/default.go | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/errors/errors.go b/errors/errors.go index ace8a074..486ae049 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -282,20 +282,20 @@ func (e *Error) Unmarshal(data []byte) error { nparts := strings.FieldsFunc(part, func(r rune) bool { return r == ':' }) - for idx := 0; idx < len(nparts); idx++ { - if len(nparts[idx+1]) < 3 { - idx++ + for idx := 0; idx < len(nparts)/2; idx += 2 { + val := strings.Trim(nparts[idx+1], `"`) + if len(val) == 0 { continue } switch { case nparts[idx] == `"id"`: - e.ID = nparts[idx+1][1 : len(nparts[idx+1])-1] + e.ID = val case nparts[idx] == `"detail"`: - e.Detail = nparts[idx+1][1 : len(nparts[idx+1])-1] + e.Detail = val case nparts[idx] == `"status"`: - e.Status = nparts[idx+1][1 : len(nparts[idx+1])-1] + e.Status = val case nparts[idx] == `"code"`: - c, err := strconv.ParseInt(nparts[idx+1], 10, 32) + c, err := strconv.ParseInt(val, 10, 32) if err != nil { return err } diff --git a/go.mod b/go.mod index 5475d650..516df56b 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/golang-jwt/jwt/v4 v4.2.0 github.com/imdario/mergo v0.3.12 github.com/patrickmn/go-cache v2.1.0+incompatible - github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4 + github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35 go.unistack.org/micro-proto/v3 v3.1.1 golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect diff --git a/go.sum b/go.sum index a665c4e5..d2e95577 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= -github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4 h1:fOH64AB0C3ixGf9emky61STvPJL3smxJg+1Zwx1oCdg= -github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I= +github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35 h1:4mohWoM/UGg1BvFFiqSPRl5uwJY3rVV0HQX0ETqauqQ= +github.com/silas/dag v0.0.0-20211117232152-9d50aa809f35/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I= go.unistack.org/micro-proto/v3 v3.1.1 h1:78qRmltwGek5kSQ9tNmDZ9TCRvZM7YDIOgzriKvabjA= go.unistack.org/micro-proto/v3 v3.1.1/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eFvlmYAx4BQS8= golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b h1:eB48h3HiRycXNy8E0Gf5e0hv7YT6Kt14L/D73G1fuwo= diff --git a/logger/default.go b/logger/default.go index 6ccd90f2..4e0ca88f 100644 --- a/logger/default.go +++ b/logger/default.go @@ -12,11 +12,11 @@ import ( ) type defaultLogger struct { + sync.RWMutex enc *json.Encoder logFunc LogFunc logfFunc LogfFunc opts Options - sync.RWMutex } // Init(opts...) should only overwrite provided options -- 2.45.2