refine goctl rpc generator
parent
db16115037
commit
72132ce399
Binary file not shown.
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 140 KiB |
@ -0,0 +1,30 @@
|
||||
package gogen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
)
|
||||
|
||||
const etcTemplate = `Name: {{.serviceName}}.rpc
|
||||
Log:
|
||||
Mode: console
|
||||
ListenOn: 127.0.0.1:8080
|
||||
Etcd:
|
||||
Hosts:
|
||||
- 127.0.0.1:6379
|
||||
Key: {{.serviceName}}.rpc
|
||||
`
|
||||
|
||||
func (g *defaultRpcGenerator) genEtc() error {
|
||||
etdDir := g.dirM[dirEtc]
|
||||
fileName := filepath.Join(etdDir, fmt.Sprintf("%v.yaml", g.Ctx.ServiceName.Lower()))
|
||||
if util.FileExists(fileName) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return util.With("etc").Parse(etcTemplate).SaveTo(map[string]interface{}{
|
||||
"serviceName": g.Ctx.ServiceName.Lower(),
|
||||
}, fileName, false)
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package gogen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||||
)
|
||||
|
||||
var etcTemplate = `{
|
||||
"Name": "{{.serviceName}}.rpc",
|
||||
"Log": {
|
||||
"Mode": "console"
|
||||
},
|
||||
"ListenOn": "127.0.0.1:8080",
|
||||
"Etcd": {
|
||||
"Hosts": ["127.0.0.1:6379"],
|
||||
"Key": "{{.serviceName}}.rpc"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
func (g *defaultRpcGenerator) genEtc() error {
|
||||
etdDir := g.dirM[dirEtc]
|
||||
fileName := filepath.Join(etdDir, fmt.Sprintf("%v.json", g.Ctx.ServiceName.Lower()))
|
||||
if util.FileExists(fileName) {
|
||||
return nil
|
||||
}
|
||||
return util.With("etc").
|
||||
Parse(etcTemplate).
|
||||
SaveTo(map[string]interface{}{
|
||||
"serviceName": g.Ctx.ServiceName.Lower(),
|
||||
}, fileName, false)
|
||||
}
|
Loading…
Reference in New Issue