fmtFieldName formats a string as a struct key Example: fmtFieldName("foo_id") Output: FooID
(s string)
| 108 | // fmtFieldName("foo_id") |
| 109 | // Output: FooID |
| 110 | func fmtFieldName(s string) string { |
| 111 | name := lintFieldName(s) |
| 112 | runes := []rune(name) |
| 113 | for i, c := range runes { |
| 114 | ok := unicode.IsLetter(c) || unicode.IsDigit(c) |
| 115 | if i == 0 { |
| 116 | ok = unicode.IsLetter(c) |
| 117 | } |
| 118 | if !ok { |
| 119 | runes[i] = '_' |
| 120 | } |
| 121 | } |
| 122 | return string(runes) |
| 123 | } |
| 124 | |
| 125 | func lintFieldName(name string) string { |
| 126 | // Fast path for simple cases: "_" and all lowercase. |
no test coverage detected