Parse errors instead of panics
This commit is contained in:
parent
1e12efce13
commit
aa1da8078a
@ -7,13 +7,14 @@ import (
|
||||
|
||||
type GenericValues map[string][]string
|
||||
|
||||
func (gv GenericValues) Parse(data any, tag string) {
|
||||
func (gv GenericValues) Parse(data any, tag string) (err error) {
|
||||
if gv == nil {
|
||||
gv = make(GenericValues)
|
||||
}
|
||||
d := reflect.ValueOf(data)
|
||||
if d.Kind() != reflect.Struct {
|
||||
panic(fmt.Errorf("expected struct input for data"))
|
||||
err = fmt.Errorf("expected struct input for data")
|
||||
return
|
||||
}
|
||||
for i := 0; i < d.NumField(); i++ {
|
||||
key, ok := d.Type().Field(i).Tag.Lookup(tag)
|
||||
@ -38,4 +39,5 @@ func (gv GenericValues) Parse(data any, tag string) {
|
||||
}
|
||||
gv[key] = v
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import (
|
||||
|
||||
type Header map[string][]string
|
||||
|
||||
func (h Header) Parse(data any) {
|
||||
GenericValues(h).Parse(data, "header")
|
||||
func (h Header) Parse(data any) error {
|
||||
return GenericValues(h).Parse(data, "header")
|
||||
}
|
||||
|
||||
func (h Header) Get(key string) (value string) {
|
||||
|
Loading…
Reference in New Issue
Block a user