errors: fix parsing
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
8f7eebc24f
commit
8546140e22
@ -282,20 +282,20 @@ func (e *Error) Unmarshal(data []byte) error {
|
|||||||
nparts := strings.FieldsFunc(part, func(r rune) bool {
|
nparts := strings.FieldsFunc(part, func(r rune) bool {
|
||||||
return r == ':'
|
return r == ':'
|
||||||
})
|
})
|
||||||
for idx := 0; idx < len(nparts); idx++ {
|
for idx := 0; idx < len(nparts)/2; idx += 2 {
|
||||||
if len(nparts[idx+1]) < 3 {
|
val := strings.Trim(nparts[idx+1], `"`)
|
||||||
idx++
|
if len(val) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case nparts[idx] == `"id"`:
|
case nparts[idx] == `"id"`:
|
||||||
e.ID = nparts[idx+1][1 : len(nparts[idx+1])-1]
|
e.ID = val
|
||||||
case nparts[idx] == `"detail"`:
|
case nparts[idx] == `"detail"`:
|
||||||
e.Detail = nparts[idx+1][1 : len(nparts[idx+1])-1]
|
e.Detail = val
|
||||||
case nparts[idx] == `"status"`:
|
case nparts[idx] == `"status"`:
|
||||||
e.Status = nparts[idx+1][1 : len(nparts[idx+1])-1]
|
e.Status = val
|
||||||
case nparts[idx] == `"code"`:
|
case nparts[idx] == `"code"`:
|
||||||
c, err := strconv.ParseInt(nparts[idx+1], 10, 32)
|
c, err := strconv.ParseInt(val, 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
|||||||
github.com/golang-jwt/jwt/v4 v4.2.0
|
github.com/golang-jwt/jwt/v4 v4.2.0
|
||||||
github.com/imdario/mergo v0.3.12
|
github.com/imdario/mergo v0.3.12
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
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
|
go.unistack.org/micro-proto/v3 v3.1.1
|
||||||
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b
|
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||||
|
4
go.sum
4
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/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 h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
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-20211117232152-9d50aa809f35 h1:4mohWoM/UGg1BvFFiqSPRl5uwJY3rVV0HQX0ETqauqQ=
|
||||||
github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
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 h1:78qRmltwGek5kSQ9tNmDZ9TCRvZM7YDIOgzriKvabjA=
|
||||||
go.unistack.org/micro-proto/v3 v3.1.1/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eFvlmYAx4BQS8=
|
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=
|
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b h1:eB48h3HiRycXNy8E0Gf5e0hv7YT6Kt14L/D73G1fuwo=
|
||||||
|
@ -12,11 +12,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type defaultLogger struct {
|
type defaultLogger struct {
|
||||||
|
sync.RWMutex
|
||||||
enc *json.Encoder
|
enc *json.Encoder
|
||||||
logFunc LogFunc
|
logFunc LogFunc
|
||||||
logfFunc LogfFunc
|
logfFunc LogfFunc
|
||||||
opts Options
|
opts Options
|
||||||
sync.RWMutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init(opts...) should only overwrite provided options
|
// Init(opts...) should only overwrite provided options
|
||||||
|
Loading…
Reference in New Issue
Block a user