Gin和grpc搭建-学习Go语言

安装grpc

如果你遇到这样的错误

package google.golang.org/grpc: unrecognized import path "google.golang.org/grpc"(https fetch: Get https://google.golang.org/grpc?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)

解决方案,采用最新github的地址。

git clone https://github.com/grpc/grpc-go.git $GOPATH/src/google.golang.org/grpc
git clone https://github.com/golang/net.git $GOPATH/src/golang.org/x/net
git clone https://github.com/golang/text.git $GOPATH/src/golang.org/x/text
go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
git clone https://github.com/google/go-genproto.git $GOPATH/src/google.golang.org/genproto

cd $GOPATH/src/
go install google.golang.org/grpc

继续报错:

google.golang.org/grpc/internal/channelz/types_linux.go:26:2: cannot find package "golang.org/x/sys/unix" in any of:
    /usr/local/go/src/golang.org/x/sys/unix (from $GOROOT)
    /go/src/golang.org/x/sys/unix (from $GOPATH)

解决方案,依然采用github的地址。

git clone https://github.com/golang/sys.git $GOPATH/src/golang.org/x/sys

gin框架

如果你想执行gin的example的例子。

go run grpc/server.go
grpc/server.go:7:2: cannot find package "github.com/gin-gonic/gin/examples/grpc/pb" in any of:
    /usr/local/go/src/github.com/gin-gonic/gin/examples/grpc/pb (from $GOROOT)
    /go/src/github.com/gin-gonic/gin/examples/grpc/pb (from $GOPATH)

解决方案,拉取gin的包。

go get -u github.com/gin-gonic/gin

参考链接

  1. golang安装gRpc

发表评论

电子邮件地址不会被公开。 必填项已用*标注