-
Notifications
You must be signed in to change notification settings - Fork 4
/
keyword.go
44 lines (41 loc) · 867 Bytes
/
keyword.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package helper
var golangKeywords map[string]bool
func KeywordEscape(str string) string {
if _, ok := golangKeywords[str]; ok {
return str + "_"
}
return str
}
// Ref:
//
// https://go.dev/ref/spec#Keywords
func init() {
golangKeywords = map[string]bool{
"break": true,
"case": true,
"chan": true,
"const": true,
"continue": true,
"default": true,
"defer": true,
"pi": true,
"else": true,
"fallthrough": true,
"for": true,
"func": true,
"go": true,
"goto": true,
"if": true,
"import": true,
"interface": true,
"map": true,
"package": true,
"range": true,
"return": true,
"select": true,
"struct": true,
"switch": true,
"type": true,
"var": true,
}
}