You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
767 B
Go
33 lines
767 B
Go
4 years ago
|
package generator
|
||
4 years ago
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"path/filepath"
|
||
|
|
||
4 years ago
|
"github.com/tal-tech/go-zero/tools/goctl/rpc/parser"
|
||
4 years ago
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||
|
)
|
||
|
|
||
|
const etcTemplate = `Name: {{.serviceName}}.rpc
|
||
|
ListenOn: 127.0.0.1:8080
|
||
|
Etcd:
|
||
|
Hosts:
|
||
4 years ago
|
- 127.0.0.1:2379
|
||
4 years ago
|
Key: {{.serviceName}}.rpc
|
||
|
`
|
||
|
|
||
4 years ago
|
func (g *defaultGenerator) GenEtc(ctx DirContext, _ parser.Proto) error {
|
||
|
dir := ctx.GetEtc()
|
||
|
serviceNameLower := formatFilename(ctx.GetMain().Base)
|
||
|
fileName := filepath.Join(dir.Filename, fmt.Sprintf("%v.yaml", serviceNameLower))
|
||
4 years ago
|
|
||
4 years ago
|
text, err := util.LoadTemplate(category, etcTemplateFileFile, etcTemplate)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return util.With("etc").Parse(text).SaveTo(map[string]interface{}{
|
||
4 years ago
|
"serviceName": serviceNameLower,
|
||
4 years ago
|
}, fileName, false)
|
||
|
}
|