2020-08-29 00:15:15 +08:00
|
|
|
package gen
|
2020-08-28 19:24:58 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/util"
|
|
|
|
"github.com/tal-tech/go-zero/tools/goctl/util/console"
|
|
|
|
)
|
|
|
|
|
2020-08-28 21:22:35 +08:00
|
|
|
const rpcTemplateText = `syntax = "proto3";
|
2020-08-28 19:24:58 +08:00
|
|
|
|
2020-08-28 21:22:35 +08:00
|
|
|
package remote;
|
2020-08-28 19:24:58 +08:00
|
|
|
|
|
|
|
message Request {
|
|
|
|
string username = 1;
|
|
|
|
string password = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
message Response {
|
|
|
|
string name = 1;
|
|
|
|
string gender = 2;
|
|
|
|
}
|
|
|
|
|
2020-08-28 21:22:35 +08:00
|
|
|
service User {
|
|
|
|
rpc Login(Request) returns(Response);
|
|
|
|
}
|
|
|
|
`
|
2020-08-28 19:24:58 +08:00
|
|
|
|
2020-08-28 21:22:35 +08:00
|
|
|
type rpcTemplate struct {
|
|
|
|
out string
|
|
|
|
console.Console
|
|
|
|
}
|
2020-08-28 19:24:58 +08:00
|
|
|
|
|
|
|
func NewRpcTemplate(out string, idea bool) *rpcTemplate {
|
|
|
|
return &rpcTemplate{
|
|
|
|
out: out,
|
|
|
|
Console: console.NewConsole(idea),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *rpcTemplate) MustGenerate() {
|
|
|
|
err := util.With("t").Parse(rpcTemplateText).SaveTo(nil, r.out, false)
|
|
|
|
r.Must(err)
|
|
|
|
r.Success("Done.")
|
|
|
|
}
|