MCPcopy
hub / github.com/gin-gonic/gin / trySetUsingParser

Function trySetUsingParser

binding/form_mapping.go:201–211  ·  view source on GitHub ↗

trySetUsingParser tries to set a custom type value based on the presence of the "parser" tag on the field. If the parser tag does not exist or does not match any of the supported parsers, gin will skip over this.

(val string, value reflect.Value, parser string)

Source from the content-addressed store, hash-verified

199// trySetUsingParser tries to set a custom type value based on the presence of the "parser" tag on the field.
200// If the parser tag does not exist or does not match any of the supported parsers, gin will skip over this.
201func trySetUsingParser(val string, value reflect.Value, parser string) (isSet bool, err error) {
202 switch parser {
203 case "encoding.TextUnmarshaler":
204 v, ok := value.Addr().Interface().(encoding.TextUnmarshaler)
205 if !ok {
206 return false, nil
207 }
208 return true, v.UnmarshalText([]byte(val))
209 }
210 return false, nil
211}
212
213func trySplit(vs []string, field reflect.StructField) (newVs []string, err error) {
214 cfTag := field.Tag.Get("collection_format")

Callers 2

setByFormFunction · 0.85
setWithProperTypeFunction · 0.85

Calls 1

UnmarshalTextMethod · 0.45

Tested by

no test coverage detected