美文网首页
Go安装 protobuf、grpc

Go安装 protobuf、grpc

作者: xuanxiao | 来源:发表于2019-05-29 17:46 被阅读0次

    1、安装 protobuf

    #安装依赖库
    sudo apt-get install autoconf automake libtool curl make g++ unzip libffi-dev -y
    #下载 protobuf:
    git clone https://github.com/protocolbuffers/protobuf.git
    #或者直接将压缩包拖入后解压
    unzip protobuf.zip
    #开始安装
    cd protobuf/
    ./autogen.sh
    ./configure
    make
    sudo make install
    # 刷新共享库
    sudo ldconfig
    #成功后需要使用命令测试
    $ protoc –h
    #安装提供Go语言的proto API接口的包
    go get -v -u github.com/golang/protobuf/proto
    #安装protoc-gen-go插件(是一个 go程序,编译它之后将可执行文件复制到\bin目录)
    go get -v -u github.com/golang/protobuf/protoc-gen-go
    #编译
    cd $GOPATH/src/github.com/golang/protobuf/protoc-gen-go/
    go build
    #将生成的 protoc-gen-go可执行文件,放在/bin目录下
    sudo cp protoc-gen-go /bin/
    

    2、安装grpc
    如果能fq:
    一个命令即可:

    go get -v -u google.golang.org/grpc
    

    如果不能fq:

    在$GOPATH/src/下
    mkdir google.golang.org
    cd $GOPATH/src/google.golang.org/
    git clone https://github.com/grpc/grpc-go  将grpc-go改名为grpc  比如:$GOPATH/src/google.golang.org/grpc
    git clone https://github.com/google/go-genproto  将go-genproto改名为genproto  比如:$GOPATH/src/google.golang.org/genproto
    
    #下面这些是大概会用到包,看情况补充
    在$GOPATH/src/下
    mkdir -p /golang.org/x
    cd $GOPATH/src/golang.org/x
    git clone https://github.com/golang/net.git  比如: $GOPATH/src/golang.org/x/net
    git clone https://github.com/golang/tools.git  比如: $GOPATH/src/golang.org/x/tools
    git clone https://github.com/golang/blog.git  比如: $GOPATH/src/golang.org/x/blog
    git clone https://github.com/golang/crypto.git  比如: $GOPATH/src/golang.org/x/crypto
    git clone https://github.com/golang/exp.git  比如: $GOPATH/src/golang.org/x/exp
    git clone https://github.com/golang/image.git  比如: $GOPATH/src/golang.org/x/image
    git clone https://github.com/golang/mobile.git 比如: $GOPATH/src/golang.org/x/mobile
    git clone https://github.com/golang/review.git  比如:$GOPATH/src/golang.org/x/review
    git clone https://github.com/golang/sys.git  比如:$GOPATH/src/golang.org/x/sys
    git clone https://github.com/golang/talks.git  比如:$GOPATH/src/golang.org/x/talks
    git clone https://github.com/golang/text.git  比如:$GOPATH/src/golang.org/x/text
    

    3、测试

    go run $GOPATH/src/google.golang.org/grpc/examples/helloworld/greeter_server/main.go
    go run $GOPATH/src/google.golang.org/grpc/examples/helloworld/greeter_client/main.go
    
    image.png 安装成功.png

    4、安装consul

    //去consul官网找到对应的地址
    wget https://releases.hashicorp.com/consul/1.5.1/consul_1.5.1_linux_amd64.zip
    unzip consul_1.5.1_linux_amd64.zip 
    mv consul /usr/local/bin/
    //验证
    consul
    
    安装成功.png

    5、安装micro

    //下面的若无法下载,自行clone
    go get -u -v github.com/go-log/log
    go get -u -v github.com/gorilla/handlers
    go get -u -v github.com/gorilla/mux
    go get -u -v github.com/gorilla/websocket
    go get -u -v github.com/mitchellh/hashstructure
    go get -u -v github.com/nlopes/slack
    go get -u -v github.com/pborman/uuid
    go get -u -v github.com/pkg/errors
    go get -u -v github.com/serenize/snaker
    go get -u -v github.com/hashicorp/consul
    go get -u -v github.com/miekg/dns
    go get -v github.com/micro/micro
    //安装
    cd $GOPATH/src/github.com/micro/micro
    go build
    mv micro /bin/
    //安装插件
    go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
    go get -u github.com/micro/protoc-gen-micro
    //测试
    micro
    
    安装成功.png

    相关文章

      网友评论

          本文标题:Go安装 protobuf、grpc

          本文链接:https://www.haomeiwen.com/subject/krxutctx.html