20 lines
365 B
Go
20 lines
365 B
Go
|
package reflectutils
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"reflect"
|
||
|
)
|
||
|
|
||
|
func GetTagValueRequired(t reflect.StructField, name string) (string, error) {
|
||
|
tag, ok := t.Tag.Lookup(name)
|
||
|
if !ok {
|
||
|
return "", fmt.Errorf("field missing required tag: %s", name)
|
||
|
}
|
||
|
return tag, nil
|
||
|
}
|
||
|
|
||
|
func GetTagValue(t reflect.StructField, name string) string {
|
||
|
tag, _ := t.Tag.Lookup(name)
|
||
|
return tag
|
||
|
}
|