github.com/anthropics/anthropic-sdk-go@v1.70.1/internal/apiquery/tag.go (about) 1 package apiquery 2 3 import ( 4 "reflect" 5 "strings" 6 ) 7 8 const queryStructTag = "query" 9 const formatStructTag = "format" 10 11 type parsedStructTag struct { 12 name string 13 omitempty bool 14 omitzero bool 15 inline bool 16 } 17 18 func parseQueryStructTag(field reflect.StructField) (tag parsedStructTag, ok bool) { 19 raw, ok := field.Tag.Lookup(queryStructTag) 20 if !ok { 21 return tag, ok 22 } 23 parts := strings.Split(raw, ",") 24 if len(parts) == 0 { 25 return tag, false 26 } 27 tag.name = parts[0] 28 for _, part := range parts[1:] { 29 switch part { 30 case "omitzero": 31 tag.omitzero = true 32 case "omitempty": 33 tag.omitempty = true 34 case "inline": 35 tag.inline = true 36 } 37 } 38 return tag, ok 39 } 40 41 func parseFormatStructTag(field reflect.StructField) (format string, ok bool) { 42 format, ok = field.Tag.Lookup(formatStructTag) 43 return format, ok 44 }