diff --git a/protoc-gen-tinyrpc/main.go b/protoc-gen-tinyrpc/main.go index 53821f7..a4ea8b3 100644 --- a/protoc-gen-tinyrpc/main.go +++ b/protoc-gen-tinyrpc/main.go @@ -42,12 +42,23 @@ func (md *rpc) Generate(plugin *protogen.Plugin) error { } fileName := f.GeneratedFilenamePrefix + ".svr.go" t := plugin.NewGeneratedFile(fileName, f.GoImportPath) - t.P("// Code generated by protoc-gen-tinyrpc.") + t.P("// Code generated by protoc-gen-tinyrpc. DO NOT EDIT.") t.P() pkg := fmt.Sprintf("package %s", f.GoPackageName) t.P(pkg) t.P() for _, s := range f.Services { + comment := fmt.Sprintf("// %sServer You need to define a struct to implement these methods and then call them\n", s.Desc.Name()) + serviceInterface := fmt.Sprintf("%stype %sServer interface{", + comment, s.Desc.Name()) + t.P(serviceInterface) + for _, m := range s.Methods { + funcCode := fmt.Sprintf("%s(args *%s, reply *%s) error", + m.Desc.Name(), m.Input.Desc.Name(), m.Output.Desc.Name()) + t.P(funcCode) + } + t.P("}") + serviceCode := fmt.Sprintf(`%stype %s struct{}`, getComments(s.Comments), s.Desc.Name()) t.P(serviceCode)