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.
go-zero/tools/goctl/api/gogen/genetc.go

46 lines
958 B
Go

4 years ago
package gogen
import (
_ "embed"
4 years ago
"fmt"
"strconv"
"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"
4 years ago
)
const (
defaultPort = 8888
etcDir = "etc"
)
//go:embed etc.tpl
var etcTemplate string
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
}
4 years ago
service := api.Service
host := "0.0.0.0"
port := strconv.Itoa(defaultPort)
4 years ago
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,
},
4 years ago
})
}