-
Notifications
You must be signed in to change notification settings - Fork 672
/
plugin_server.go
41 lines (31 loc) · 970 Bytes
/
plugin_server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (C) 2019-2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package plugin
import (
"context"
"google.golang.org/protobuf/types/known/emptypb"
"github.com/ava-labs/avalanchego/app"
pluginpb "github.com/ava-labs/avalanchego/proto/pb/plugin"
)
// Server wraps a node so it can be served with the hashicorp plugin harness
type Server struct {
pluginpb.UnsafeNodeServer
app app.App
}
func NewServer(app app.App) *Server {
return &Server{
app: app,
}
}
func (s *Server) Start(context.Context, *emptypb.Empty) (*emptypb.Empty, error) {
return &emptypb.Empty{}, s.app.Start()
}
func (s *Server) Stop(context.Context, *emptypb.Empty) (*emptypb.Empty, error) {
return &emptypb.Empty{}, s.app.Stop()
}
func (s *Server) ExitCode(context.Context, *emptypb.Empty) (*pluginpb.ExitCodeResponse, error) {
exitCode, err := s.app.ExitCode()
return &pluginpb.ExitCodeResponse{
ExitCode: int32(exitCode),
}, err
}