Added fix for Header.Parse

This commit is contained in:
some 2024-10-07 18:34:43 -04:00
parent 8436196447
commit 7e1453e72f
Signed by: some
GPG Key ID: 65D0589220B9BFC8

View File

@ -17,8 +17,8 @@ func (h Header) Parse(data any) {
panic(fmt.Errorf("expected struct input for data")) panic(fmt.Errorf("expected struct input for data"))
} }
for i := 0; i < d.NumField(); i++ { for i := 0; i < d.NumField(); i++ {
key := d.Type().Field(i).Tag.Get("header") key, ok := d.Type().Field(i).Tag.Lookup("header")
if key == "" { if !ok || key == "" {
continue continue
} }
v := make([]string, 0) v := make([]string, 0)
@ -32,11 +32,12 @@ func (h Header) Parse(data any) {
if item.Kind() == reflect.Pointer || item.Kind() == reflect.Interface { if item.Kind() == reflect.Pointer || item.Kind() == reflect.Interface {
item = item.Elem() item = item.Elem()
} }
v = append(v, fmt.Sprint(item.Interface())) v = append(v, fmt.Sprintf("%s", item.Interface()))
} }
} else { } else {
v = append(v, fmt.Sprint(val.Interface())) v = append(v, fmt.Sprintf("%s", val.Interface()))
} }
h[key] = v
} }
} }