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

Function GenerateMetaMapConsts

pkg/gogen/gogen.go:36–74  ·  view source on GitHub ↗
(buf *strings.Builder, constPrefix string, rtype reflect.Type, embedded bool)

Source from the content-addressed store, hash-verified

34}
35
36func GenerateMetaMapConsts(buf *strings.Builder, constPrefix string, rtype reflect.Type, embedded bool) {
37 if !embedded {
38 buf.WriteString("const (\n")
39 } else {
40 buf.WriteString("\n")
41 }
42 var lastBeforeColon = ""
43 isFirst := true
44 for idx := 0; idx < rtype.NumField(); idx++ {
45 field := rtype.Field(idx)
46 if field.PkgPath != "" {
47 continue
48 }
49 if field.Anonymous {
50 var embeddedBuf strings.Builder
51 GenerateMetaMapConsts(&embeddedBuf, constPrefix, field.Type, true)
52 buf.WriteString(embeddedBuf.String())
53 continue
54 }
55 fieldName := field.Name
56 jsonTag := utilfn.GetJsonTag(field)
57 if jsonTag == "" {
58 jsonTag = fieldName
59 }
60 beforeColon := getBeforeColonPart(jsonTag)
61 if beforeColon != lastBeforeColon {
62 if !isFirst {
63 buf.WriteString("\n")
64 }
65 lastBeforeColon = beforeColon
66 }
67 cname := constPrefix + fieldName
68 buf.WriteString(fmt.Sprintf("\t%-40s = %q\n", cname, jsonTag))
69 isFirst = false
70 }
71 if !embedded {
72 buf.WriteString(")\n")
73 }
74}
75
76func GenMethod_Call(buf *strings.Builder, methodDecl *wshrpc.WshRpcMethodDecl) {
77 fmt.Fprintf(buf, "// command %q, wshserver.%s\n", methodDecl.Command, methodDecl.MethodName)

Callers 2

Calls 4

GetJsonTagFunction · 0.92
getBeforeColonPartFunction · 0.85
WriteStringMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected