gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/config/bytes-parser.go (about) 1 package config 2 3 import ( 4 "gitee.com/sy_183/go-common/errors" 5 ) 6 7 type bytesParser struct { 8 bytes []byte 9 typ Type 10 } 11 12 func (p *bytesParser) Unmarshal(c interface{}) error { 13 if p.typ.Id == TypeUnknown.Id { 14 var es error 15 for _, typ := range types { 16 if typ.Unmarshaler != nil { 17 if err := typ.Unmarshaler(p.bytes, c); err != nil { 18 // retry next unmarshaler parse config 19 errors.Append(es, err) 20 continue 21 } 22 // parse config success 23 break 24 } 25 } 26 } else { 27 if err := p.typ.Unmarshaler(p.bytes, c); err != nil { 28 return err 29 } 30 } 31 32 return nil 33 }