Function
getObjectTagByFieldName
(obj any, fieldName string)
Source from the content-addressed store, hash-verified
| 262 | } |
| 263 | |
| 264 | func getObjectTagByFieldName(obj any, fieldName string) (tag string) { |
| 265 | defer func() { |
| 266 | if err := recover(); err != nil { |
| 267 | log.Error(err) |
| 268 | } |
| 269 | }() |
| 270 | |
| 271 | objT := reflect.TypeOf(obj) |
| 272 | objT = objT.Elem() |
| 273 | |
| 274 | structField, exists := objT.FieldByName(fieldName) |
| 275 | if !exists { |
| 276 | return "" |
| 277 | } |
| 278 | tag = structField.Tag.Get("json") |
| 279 | if len(tag) == 0 { |
| 280 | return structField.Tag.Get("form") |
| 281 | } |
| 282 | return tag |
| 283 | } |
Tested by
no test coverage detected