MCPcopy
hub / github.com/jmoiron/sqlx / parseName

Function parseName

reflectx/reflect.go:282–320  ·  reflectx/reflect.go::parseName

parseName parses the tag and the target name for the given field using the tagName (eg 'json' for `json:"foo"` tags), mapFunc for mapping the field's name to a target name, and tagMapFunc for mapping the tag to a target name.

(field reflect.StructField, tagName string, mapFunc, tagMapFunc mapf)

Source from the content-addressed store, hash-verified

280// field's name to a target name, and tagMapFunc for mapping the tag to
281// a target name.
282func parseName(field reflect.StructField, tagName string, mapFunc, tagMapFunc mapf) (tag, fieldName string) {
283 // first, set the fieldName to the field's name
284 fieldName = field.Name
285 // if a mapFunc is set, use that to override the fieldName
286 if mapFunc != nil {
287 fieldName = mapFunc(fieldName)
288 }
289
290 // if there's no tag to look for, return the field name
291 if tagName == "" {
292 return "", fieldName
293 }
294
295 // if this tag is not set using the normal convention in the tag,
296 // then return the fieldname.. this check is done because according
297 // to the reflect documentation:
298 // If the tag does not have the conventional format,
299 // the value returned by Get is unspecified.
300 // which doesn't sound great.
301 if !strings.Contains(string(field.Tag), tagName+":") {
302 return "", fieldName
303 }
304
305 // at this point we're fairly sure that we have a tag, so lets pull it out
306 tag = field.Tag.Get(tagName)
307
308 // if we have a mapper function, call it on the whole tag
309 // XXX: this is a change from the old version, which pulled out the name
310 // before the tagMapFunc could be run, but I think this is the right way
311 if tagMapFunc != nil {
312 tag = tagMapFunc(tag)
313 }
314
315 // finally, split the options from the name
316 parts := strings.Split(tag, ",")
317 fieldName = parts[0]
318
319 return tag, fieldName
320}
321
322// parseOptions parses options out of a tag string, skipping the name
323func parseOptions(tag string) map[string]string {

Callers 1

getMappingFunction · 0.85

Calls 1

GetMethod · 0.45

Tested by

no test coverage detected