-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcounter.go
51 lines (43 loc) · 1.14 KB
/
counter.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
45
46
47
48
49
50
51
package main
import (
"fmt"
"path/filepath"
"strings"
)
type counter struct {
opts *options
modelName string
daoClassName string
daoVariableName string
daoPkgPath string
daoPkgName string
daoOutputDir string
daoOutputFile string
daoPrefixName string
collectionName string
}
func newCounter(opts *options) *counter {
c := &counter{}
c.opts = opts
c.modelName = toPascalCase(opts.counterName)
c.daoClassName = toPascalCase(c.modelName)
c.daoVariableName = toCamelCase(c.modelName)
c.daoOutputFile = fmt.Sprintf("%s.go", toFileName(c.modelName, c.opts.fileNameStyle))
c.collectionName = toUnderscoreCase(c.modelName)
dir := strings.TrimSuffix(opts.daoDir, "/")
if opts.subPkgEnable {
c.daoOutputDir = dir + "/" + toPackagePath(c.modelName, c.opts.subPkgStyle)
} else {
c.daoOutputDir = dir
c.daoPrefixName = toPascalCase(c.modelName)
}
return c
}
func (c *counter) setDaoPkgPath(path string) {
if c.opts.subPkgEnable {
c.daoPkgPath = path + "/" + toPackagePath(c.modelName, c.opts.subPkgStyle)
} else {
c.daoPkgPath = path
}
c.daoPkgName = toPackageName(filepath.Base(c.daoPkgPath))
}