/
grpc_version.go
41 lines (34 loc) · 1.09 KB
/
grpc_version.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
package yakgrpc
import (
"context"
"strings"
"github.com/yaklang/yaklang/common/consts"
"github.com/yaklang/yaklang/common/utils"
"github.com/yaklang/yaklang/common/yakgrpc/ypb"
)
func (s *Server) Version(ctx context.Context, _ *ypb.Empty) (*ypb.VersionResponse, error) {
return &ypb.VersionResponse{Version: consts.GetPalmVersion()}, nil
}
func (s *Server) YakVersionAtLeast(ctx context.Context, req *ypb.YakVersionAtLeastRequest) (*ypb.GeneralResponse, error) {
version := req.GetYakVersion()
atLeastVersion := req.GetAtLeastVersion()
if version == "" {
version = consts.GetYakVersion()
}
if strings.HasPrefix(version, "v") {
version = version[1:]
}
if strings.HasPrefix(atLeastVersion, "v") {
atLeastVersion = atLeastVersion[1:]
}
ok := false
if version == "dev" || version == "" {
ok = true
} else {
ok = utils.VersionGreaterEqual(version, atLeastVersion)
}
return &ypb.GeneralResponse{Ok: ok}, nil
}
func (s *Server) GetMachineID(ctx context.Context, _ *ypb.Empty) (*ypb.GetMachineIDResponse, error) {
return &ypb.GetMachineIDResponse{MachineID: utils.GetMachineCode()}, nil
}