MCPcopy Index your code
hub / github.com/wailsapp/wails / getJSONFieldName

Method getJSONFieldName

v2/internal/typescriptify/typescriptify.go:589–631  ·  view source on GitHub ↗
(field reflect.StructField, isPtr bool)

Source from the content-addressed store, hash-verified

587}
588
589func (t *TypeScriptify) getJSONFieldName(field reflect.StructField, isPtr bool) string {
590 jsonFieldName := ""
591 // function, complex, and channel types cannot be json-encoded
592 if field.Type.Kind() == reflect.Chan ||
593 field.Type.Kind() == reflect.Func ||
594 field.Type.Kind() == reflect.UnsafePointer ||
595 field.Type.Kind() == reflect.Complex128 ||
596 field.Type.Kind() == reflect.Complex64 {
597 return ""
598 }
599 jsonTag, hasTag := field.Tag.Lookup("json")
600 if !hasTag && field.IsExported() {
601 jsonFieldName = field.Name
602 if isPtr {
603 jsonFieldName += "?"
604 }
605 }
606 if len(jsonTag) > 0 {
607 jsonTagParts := strings.Split(jsonTag, ",")
608 if len(jsonTagParts) > 0 {
609 jsonFieldName = strings.Trim(jsonTagParts[0], t.Indent)
610 }
611 hasOmitEmpty := false
612 ignored := false
613 for _, t := range jsonTagParts {
614 if t == "" {
615 break
616 }
617 if t == "omitempty" {
618 hasOmitEmpty = true
619 break
620 }
621 if t == "-" {
622 ignored = true
623 break
624 }
625 }
626 if !ignored && isPtr || hasOmitEmpty {
627 jsonFieldName = fmt.Sprintf("%s?", jsonFieldName)
628 }
629 }
630 return jsonFieldName
631}
632
633func (t *TypeScriptify) convertType(depth int, typeOf reflect.Type, customCode map[string]string) (string, error) {
634 if _, found := t.alreadyConverted[typeOf.String()]; found { // Already converted

Callers 2

deepFieldsMethod · 0.95
convertTypeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected