Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

A new interface is added to the server generated file #26

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion protoc-gen-tinyrpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading