Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Generate ServiceNameClient interface akin to gRPC's plugin #178

Open
meling opened this issue Mar 11, 2024 · 0 comments
Open

feat: Generate ServiceNameClient interface akin to gRPC's plugin #178

meling opened this issue Mar 11, 2024 · 0 comments

Comments

@meling
Copy link
Member

meling commented Mar 11, 2024

The gRPC plugin generates a ServiceNameClient interface like this one:

// MultiPaxosClient is the client API for MultiPaxos service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type MultiPaxosClient interface {
	Prepare(ctx context.Context, in *PrepareMsg, opts ...grpc.CallOption) (*PromiseMsg, error)
	Accept(ctx context.Context, in *AcceptMsg, opts ...grpc.CallOption) (*LearnMsg, error)
	Commit(ctx context.Context, in *LearnMsg, opts ...grpc.CallOption) (*Empty, error)
	ClientHandle(ctx context.Context, in *Value, opts ...grpc.CallOption) (*Response, error)
}

Such an interface can be useful for testing.

Since the Gorums plugin replaces the gRPC plugin because it generates overlapping types, we should provide the relevant interface as part of code generation in the _gorums.pb.go file. This should be straightforward since we already generate methods on the Configuration type, such as this one:

var quorumCallSignature = `func (c *Configuration) {{$method}}(` +
	`ctx {{$context}}, in *{{$in}}` +
	`{{perNodeFnType .GenFile .Method ", f"}})` +
	`(resp *{{$customOut}}, err error) {
`

We already generate the corresponding server-side interface here:

var serverInterface = `
{{$genFile := .GenFile}}
{{range .Services -}}
{{$service := .GoName}}
// {{$service}} is the server-side API for the {{$service}} Service
type {{$service}} interface {
	{{- range .Methods}}
	{{- if isOneway .}}
	{{.GoName}}(ctx {{$context}}, request *{{in $genFile .}})
	{{- else if correctableStream .}}
	{{.GoName}}(ctx {{$context}}, request *{{in $genFile .}}, send func(response *{{out $genFile .}}) error) error
	{{- else}}
	{{.GoName}}(ctx {{$context}}, request *{{in $genFile .}}) (response *{{out $genFile .}}, err error)
	{{- end}}
	{{- end}}
}
{{- end}}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant