Feature: Add goctl env (#1557)
This commit is contained in:
44
tools/goctl/pkg/protocgengogrpc/protocgengogrpc.go
Normal file
44
tools/goctl/pkg/protocgengogrpc/protocgengogrpc.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package protocgengogrpc
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/tools/goctl/pkg/goctl"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/pkg/golang"
|
||||
"github.com/zeromicro/go-zero/tools/goctl/rpc/execx"
|
||||
"github.com/zeromicro/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
|
||||
}
|
||||
Reference in New Issue
Block a user