mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 09:40:24 +08:00
e76f44a35b
* reactor rpc generation * update flag * update command * update command * update unit test * delete test file * optimize code * update doc * update gen pb * rename target dir * update mysql data type convert rule * add done flag * optimize req/reply parameter * optimize req/reply parameter * remove waste code * remove duplicate parameter * format code * format code * optimize naming * reactor rpcv2 to rpc * remove new line * format code * rename underline to snake * reactor getParentPackage * remove debug log * reactor background
48 lines
920 B
Go
48 lines
920 B
Go
package generator
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
|
"github.com/tal-tech/go-zero/tools/goctl/util/stringx"
|
|
)
|
|
|
|
const rpcTemplateText = `syntax = "proto3";
|
|
|
|
package {{.package}};
|
|
|
|
message Request {
|
|
string ping = 1;
|
|
}
|
|
|
|
message Response {
|
|
string pong = 1;
|
|
}
|
|
|
|
service {{.serviceName}} {
|
|
rpc Ping(Request) returns(Response);
|
|
}
|
|
`
|
|
|
|
func ProtoTmpl(out string) error {
|
|
protoFilename := filepath.Base(out)
|
|
serviceName := stringx.From(strings.TrimSuffix(protoFilename, filepath.Ext(protoFilename)))
|
|
text, err := util.LoadTemplate(category, rpcTemplateFile, rpcTemplateText)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
dir := filepath.Dir(out)
|
|
err = util.MkdirIfNotExist(dir)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = util.With("t").Parse(text).SaveTo(map[string]string{
|
|
"package": serviceName.UnTitle(),
|
|
"serviceName": serviceName.Title(),
|
|
}, out, false)
|
|
return err
|
|
}
|