forked from pachyderm/pachyderm
/
api_server.go
47 lines (37 loc) · 1.21 KB
/
api_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
42
43
44
45
46
47
package version
import (
"fmt"
pb "github.com/pachyderm/pachyderm/src/client/version/versionpb"
"github.com/gogo/protobuf/types"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
type apiServer struct {
version *pb.Version
options APIServerOptions
}
func newAPIServer(version *pb.Version, options APIServerOptions) *apiServer {
return &apiServer{version, options}
}
func (a *apiServer) GetVersion(ctx context.Context, request *types.Empty) (response *pb.Version, err error) {
return a.version, nil
}
// APIServerOptions are options when creating a new APIServer.
type APIServerOptions struct {
DisableLogging bool
}
// NewAPIServer creates a new APIServer for the given Version.
func NewAPIServer(version *pb.Version, options APIServerOptions) pb.APIServer {
return newAPIServer(version, options)
}
// GetServerVersion gets the server *Version given the *grpc.ClientConn.
func GetServerVersion(clientConn *grpc.ClientConn) (*pb.Version, error) {
return pb.NewAPIClient(clientConn).GetVersion(
context.Background(),
&types.Empty{},
)
}
// String returns a string representation of the Version.
func String(v *pb.Version) string {
return fmt.Sprintf("%d.%d.%d%s", v.Major, v.Minor, v.Micro, v.Additional)
}