Skip to content

Commit

Permalink
tiny refactor to get field name tag from a method
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Sep 6, 2023
1 parent 2d282ec commit aadda03
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,12 +992,15 @@ func ignoredByJSONSchemaTags(tags []string) bool {
return tags[0] == "-"
}

func (r *Reflector) reflectFieldName(f reflect.StructField) (string, bool, bool, bool) {
tagKey := r.FieldNameTag
if tagKey == "" {
tagKey = "json"
func (r *Reflector) fieldNameTag() string {
if r.FieldNameTag != "" {
return r.FieldNameTag
}
jsonTagString := f.Tag.Get(tagKey)
return "json"
}

func (r *Reflector) reflectFieldName(f reflect.StructField) (string, bool, bool, bool) {
jsonTagString := f.Tag.Get(r.fieldNameTag())
jsonTags := strings.Split(jsonTagString, ",")

if ignoredByJSONTags(jsonTags) {
Expand Down

0 comments on commit aadda03

Please sign in to comment.