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