Skip to content

Commit 98dac51

Browse files
committed
Allow passing server options to the gRPC server
This commit modifies the plugin configuration to support passing in any desired `grpc.ServerOptions`. This can be used for logging, middlewares, credentials etc. Signed-off-by: David Bond <davidsbond93@gmail.com>
1 parent 65720ec commit 98dac51

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

plugin.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ type (
4545
// The Commands the plugin is capable of handling. When attempting to use a command that does not exist within
4646
// the plugin, an ErrUnknownCommand error is returned to the caller.
4747
Commands []CommandHandler
48+
// Any ServerOptions to apply to the gRPC server. This could be middleware, keepalives credentials etc.
49+
ServerOptions []grpc.ServerOption
4850
}
4951

5052
// The CommandHandler interface describes types that act as individual commands a plugin can handle. Plugin authors should
@@ -127,7 +129,7 @@ func Run(config Config) {
127129
}
128130

129131
func startPlugin(ctx context.Context, config Config, id, version string) error {
130-
server := grpc.NewServer()
132+
server := grpc.NewServer(config.ServerOptions...)
131133

132134
info := plugin.Info{
133135
Name: config.Name,
@@ -231,7 +233,7 @@ func Use(ctx context.Context, path string) (*Plugin, error) {
231233
}
232234

233235
if info.Name != name {
234-
return nil, fmt.Errorf("%w: %q", ErrUnexpectedName, info.Name)
236+
return nil, fmt.Errorf("%w: expected %q, got %q", ErrUnexpectedName, name, info.Name)
235237
}
236238

237239
p.info = info

0 commit comments

Comments
 (0)