(field reflect.StructField)
| 247 | } |
| 248 | |
| 249 | func ParseJSONTag(field reflect.StructField) (JsonFieldInfo, bool) { |
| 250 | tag := field.Tag.Get("json") |
| 251 | |
| 252 | // Ignore field |
| 253 | if tag == "-" { |
| 254 | return JsonFieldInfo{}, false |
| 255 | } |
| 256 | |
| 257 | name := field.Name |
| 258 | var opts []string |
| 259 | var omitEmpty, asString bool |
| 260 | |
| 261 | if tag != "" { |
| 262 | parts := strings.Split(tag, ",") |
| 263 | if parts[0] != "" { |
| 264 | name = parts[0] |
| 265 | } |
| 266 | if len(parts) > 1 { |
| 267 | opts = parts[1:] |
| 268 | for _, opt := range opts { |
| 269 | switch opt { |
| 270 | case "omitempty": |
| 271 | omitEmpty = true |
| 272 | case "string": |
| 273 | asString = true |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | return JsonFieldInfo{ |
| 280 | FieldName: name, |
| 281 | OmitEmpty: omitEmpty, |
| 282 | AsString: asString, |
| 283 | Options: opts, |
| 284 | }, true |
| 285 | } |
| 286 | |
| 287 | // TruncateString truncates a string to maxLen runes (not bytes). |
| 288 | // If the string is longer than maxLen, it truncates to maxLen-3 and appends "...". |
no test coverage detected