2020-11-05 14:12:47 +08:00
|
|
|
package generator
|
2020-08-28 19:24:58 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2020-11-05 14:12:47 +08:00
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/rpc/parser"
|
2020-08-28 19:24:58 +08:00
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
|
|
|
)
|
|
|
|
|
2020-08-28 21:22:35 +08:00
|
|
|
const configTemplate = `package config
|
2020-08-28 19:24:58 +08:00
|
|
|
|
2020-09-18 11:41:52 +08:00
|
|
|
import "github.com/tal-tech/go-zero/zrpc"
|
2020-08-28 19:24:58 +08:00
|
|
|
|
2020-08-28 21:22:35 +08:00
|
|
|
type Config struct {
|
2020-09-18 11:41:52 +08:00
|
|
|
zrpc.RpcServerConf
|
2020-08-28 21:22:35 +08:00
|
|
|
}
|
2020-08-28 19:24:58 +08:00
|
|
|
`
|
|
|
|
|
2020-11-18 15:32:53 +08:00
|
|
|
func (g *defaultGenerator) GenConfig(ctx DirContext, _ parser.Proto, namingStyle NamingStyle) error {
|
2020-11-05 14:12:47 +08:00
|
|
|
dir := ctx.GetConfig()
|
2020-11-18 15:32:53 +08:00
|
|
|
fileName := filepath.Join(dir.Filename, formatFilename("config", namingStyle)+".go")
|
2020-08-28 19:24:58 +08:00
|
|
|
if util.FileExists(fileName) {
|
|
|
|
return nil
|
|
|
|
}
|
2020-10-21 14:59:35 +08:00
|
|
|
|
|
|
|
text, err := util.LoadTemplate(category, configTemplateFileFile, configTemplate)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return ioutil.WriteFile(fileName, []byte(text), os.ModePerm)
|
2020-08-28 19:24:58 +08:00
|
|
|
}
|