-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstant.go
43 lines (34 loc) · 900 Bytes
/
constant.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
package main
import (
"fmt"
"strings"
)
type Constant struct {
ResourceOptions
}
func (c *Constant) GetDir() string {
return "constants"
}
func (c *Constant) GetFileName() string {
return c.ResourceOptions.Domain + "-constants.js"
}
func (c *Constant) GetFileContent() string {
domainFirstCharUpper := strings.ToUpper(c.Domain[:1]) + c.Domain[1:]
return fmt.Sprintf(c.getTemplate(), domainFirstCharUpper, c.Constant)
}
func (c *Constant) getTemplate() string {
content := "var keyMirror = require('keymirror');\n\n" +
"var %[1]sConstants = keyMirror({\n";
if c.IsApi {
content = content +
" %[2]s: null,\n" +
" %[2]s_SUCCESS: null\n"
} else {
content = content +
" %[2]s: null\n"
}
content = content +
"});\n\n" +
"module.exports = %[1]sConstants;"
return content
}