forked from zeromicro/go-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protocgengogrpc.go
44 lines (38 loc) · 1.01 KB
/
protocgengogrpc.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
package protocgengogrpc
import (
"strings"
"github.com/sanhuanshisanshao/go-zero/tools/goctl/pkg/goctl"
"github.com/sanhuanshisanshao/go-zero/tools/goctl/pkg/golang"
"github.com/sanhuanshisanshao/go-zero/tools/goctl/rpc/execx"
"github.com/sanhuanshisanshao/go-zero/tools/goctl/util/env"
)
const (
Name = "protoc-gen-go-grpc"
url = "google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest"
)
func Install(cacheDir string) (string, error) {
return goctl.Install(cacheDir, Name, func(dest string) (string, error) {
err := golang.Install(url)
return dest, err
})
}
func Exists() bool {
_, err := env.LookUpProtocGenGoGrpc()
return err == nil
}
// Version is used to get the version of the protoc-gen-go-grpc plugin.
func Version() (string, error) {
path, err := env.LookUpProtocGenGoGrpc()
if err != nil {
return "", err
}
version, err := execx.Run(path+" --version", "")
if err != nil {
return "", err
}
fields := strings.Fields(version)
if len(fields) > 1 {
return fields[1], nil
}
return "", nil
}