MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / ParseJSONTag

Function ParseJSONTag

tsunami/util/util.go:249–285  ·  view source on GitHub ↗
(field reflect.StructField)

Source from the content-addressed store, hash-verified

247}
248
249func 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 "...".

Callers 2

createStructDefinitionFunction · 0.92
collectStructDefsFunction · 0.92

Calls 1

GetMethod · 0.45

Tested by

no test coverage detected