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.
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
4 years ago
|
package generator
|
||
4 years ago
|
|
||
|
import (
|
||
4 years ago
|
"fmt"
|
||
4 years ago
|
|
||
4 years ago
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
||
4 years ago
|
"github.com/urfave/cli"
|
||
4 years ago
|
)
|
||
|
|
||
4 years ago
|
const (
|
||
|
category = "rpc"
|
||
|
callTemplateFile = "call.tpl"
|
||
|
callInterfaceFunctionTemplateFile = "call-interface-func.tpl"
|
||
|
callFunctionTemplateFile = "call-func.tpl"
|
||
|
configTemplateFileFile = "config.tpl"
|
||
|
etcTemplateFileFile = "etc.tpl"
|
||
|
logicTemplateFileFile = "logic.tpl"
|
||
|
logicFuncTemplateFileFile = "logic-func.tpl"
|
||
|
mainTemplateFile = "main.tpl"
|
||
|
serverTemplateFile = "server.tpl"
|
||
|
serverFuncTemplateFile = "server-func.tpl"
|
||
|
svcTemplateFile = "svc.tpl"
|
||
|
rpcTemplateFile = "template.tpl"
|
||
|
)
|
||
4 years ago
|
|
||
4 years ago
|
var templates = map[string]string{
|
||
|
callTemplateFile: callTemplateText,
|
||
|
callInterfaceFunctionTemplateFile: callInterfaceFunctionTemplate,
|
||
|
callFunctionTemplateFile: callFunctionTemplate,
|
||
|
configTemplateFileFile: configTemplate,
|
||
|
etcTemplateFileFile: etcTemplate,
|
||
|
logicTemplateFileFile: logicTemplate,
|
||
|
logicFuncTemplateFileFile: logicFunctionTemplate,
|
||
|
mainTemplateFile: mainTemplate,
|
||
|
serverTemplateFile: serverTemplate,
|
||
|
serverFuncTemplateFile: functionTemplate,
|
||
|
svcTemplateFile: svcTemplate,
|
||
|
rpcTemplateFile: rpcTemplateText,
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func GenTemplates(_ *cli.Context) error {
|
||
|
return util.InitTemplates(category, templates)
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func RevertTemplate(name string) error {
|
||
|
content, ok := templates[name]
|
||
|
if !ok {
|
||
|
return fmt.Errorf("%s: no such file name", name)
|
||
|
}
|
||
|
return util.CreateTemplate(category, name, content)
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
func Clean() error {
|
||
|
return util.Clean(category)
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
func Update(category string) error {
|
||
|
err := Clean()
|
||
|
if err != nil {
|
||
|
return err
|
||
4 years ago
|
}
|
||
4 years ago
|
return util.InitTemplates(category, templates)
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func GetCategory() string {
|
||
|
return category
|
||
4 years ago
|
}
|