2020-07-29 17:11:41 +08:00
|
|
|
package gogen
|
|
|
|
|
|
|
|
import (
|
2022-04-04 13:12:05 +08:00
|
|
|
_ "embed"
|
2020-07-29 17:11:41 +08:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
2022-01-25 23:15:07 +08:00
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/api/spec"
|
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/config"
|
|
|
|
"github.com/zeromicro/go-zero/tools/goctl/util/format"
|
2020-07-29 17:11:41 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
defaultPort = 8888
|
|
|
|
etcDir = "etc"
|
|
|
|
)
|
|
|
|
|
2022-04-04 13:12:05 +08:00
|
|
|
//go:embed etc.tpl
|
|
|
|
var etcTemplate string
|
|
|
|
|
2020-11-24 15:11:18 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-07-29 17:11:41 +08:00
|
|
|
service := api.Service
|
2021-01-11 15:10:51 +08:00
|
|
|
host := "0.0.0.0"
|
|
|
|
port := strconv.Itoa(defaultPort)
|
2020-07-29 17:11:41 +08:00
|
|
|
|
2021-01-09 00:17:23 +08:00
|
|
|
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,
|
|
|
|
},
|
2020-07-29 17:11:41 +08:00
|
|
|
})
|
|
|
|
}
|