mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 17:52:49 +08:00
ee19fb736b
* feature: refactor api parse to g4 * new g4 parser * add CHANGE_LOG.MD * refactor * fix byte bug * refactor * optimized * optimized * revert * update readme.md * update readme.md * update readme.md * update readme.md * remove no need * fix java gen * add upgrade * resolve confilits Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
46 lines
974 B
Go
46 lines
974 B
Go
package gogen
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/api/spec"
|
|
"github.com/tal-tech/go-zero/tools/goctl/config"
|
|
"github.com/tal-tech/go-zero/tools/goctl/util/format"
|
|
)
|
|
|
|
const (
|
|
defaultPort = 8888
|
|
etcDir = "etc"
|
|
etcTemplate = `Name: {{.serviceName}}
|
|
Host: {{.host}}
|
|
Port: {{.port}}
|
|
`
|
|
)
|
|
|
|
func genEtc(dir string, cfg *config.Config, api *spec.ApiSpec) error {
|
|
filename, err := format.FileNamingFormat(cfg.NamingFormat, api.Service.Name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
service := api.Service
|
|
host := "0.0.0.0"
|
|
port := strconv.Itoa(defaultPort)
|
|
|
|
return genFile(fileGenConfig{
|
|
dir: dir,
|
|
subdir: etcDir,
|
|
filename: fmt.Sprintf("%s.yaml", filename),
|
|
templateName: "etcTemplate",
|
|
category: category,
|
|
templateFile: etcTemplateFile,
|
|
builtinTemplate: etcTemplate,
|
|
data: map[string]string{
|
|
"serviceName": service.Name,
|
|
"host": host,
|
|
"port": port,
|
|
},
|
|
})
|
|
}
|