MCPcopy Create free account
hub / github.com/goadesign/goa / Goify

Function Goify

codegen/goify.go:16–38  ·  view source on GitHub ↗

Goify makes a valid Go identifier out of any string. It does that by removing any non letter and non digit character and by making sure the first character is a letter or "_". Goify produces a "CamelCase" version of the string, if firstUpper is true the first character of the identifier is uppercase

(str string, firstUpper bool)

Source from the content-addressed store, hash-verified

14// firstUpper is true the first character of the identifier is uppercase
15// otherwise it's lowercase.
16func Goify(str string, firstUpper bool) string {
17 // Optimize trivial case
18 if str == "" {
19 return ""
20 }
21
22 // Remove optional suffix that defines corresponding transport specific
23 // name.
24 idx := strings.Index(str, ":")
25 if idx > 0 {
26 str = str[:idx]
27 }
28
29 str = CamelCase(str, firstUpper, true)
30 if str == "" {
31 // All characters are invalid. Produce a default value.
32 if firstUpper {
33 return "Val"
34 }
35 return "val"
36 }
37 return fixReservedGo(str)
38}
39
40// GoifyAtt honors any struct:field:name meta set on the attribute and calls
41// Goify with the tag value if present or the given name otherwise.

Callers 15

endpointParserFunction · 0.92
ExampleServerFunction · 0.92
dummyMultipartFileFunction · 0.92
analyzeMethod · 0.92
buildPayloadDataMethod · 0.92
buildResultDataMethod · 0.92
buildResponsesMethod · 0.92
buildErrorsDataMethod · 0.92
buildRequestBodyTypeMethod · 0.92
buildResponseBodyTypeMethod · 0.92
extractPathParamsMethod · 0.92
extractQueryParamsMethod · 0.92

Calls 2

CamelCaseFunction · 0.85
fixReservedGoFunction · 0.85

Tested by 1

TestGoifyFunction · 0.68