MCPcopy Index your code
hub / github.com/coder/coder / jsonSegmentToGoName

Function jsonSegmentToGoName

scripts/modeloptionsgen/main.go:190–208  ·  view source on GitHub ↗

jsonSegmentToGoName converts a snake_case JSON segment to a PascalCase Go field name using common conventions.

(seg string)

Source from the content-addressed store, hash-verified

188// jsonSegmentToGoName converts a snake_case JSON segment to a
189// PascalCase Go field name using common conventions.
190func jsonSegmentToGoName(seg string) string {
191 words := strings.Split(seg, "_")
192 var b strings.Builder
193 for _, w := range words {
194 if w == "" {
195 continue
196 }
197 // Handle common acronyms.
198 upper := strings.ToUpper(w)
199 switch upper {
200 case "ID", "URL", "IP", "HTTP", "JSON", "API", "UI":
201 _, _ = b.WriteString(upper)
202 default:
203 _, _ = b.WriteString(strings.ToUpper(w[:1]))
204 _, _ = b.WriteString(w[1:])
205 }
206 }
207 return b.String()
208}
209
210// goTypeToSchemaType maps a Go reflect.Type to a JSON schema type
211// string.

Callers 1

goFieldPathFunction · 0.85

Calls 2

WriteStringMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected