zoukankan      html  css  js  c++  java
  • golang--安装golang并安装grpc-grpcgateway环境

    安装goland环境

    下载golang安装包,国内环境打开https://studygolang.com/dl,国外环境打开https://golang.google.cn/dl/下载对应系统的安装包,这里以linux环境为例。

    wget https://dl.google.com/go/go1.12.8.linux-amd64.tar.gz
    

    执行安装

    // 解压
    tar xvf go1.12.8.linux-amd64.tar.gz
    
    // 移动目录到系统目录
    mv go /usr/local
    

    配置环境变量,写入GOROOT、GOPATH等必要信息

    vi /etc/profile
    
    // 写入GOPATH、GOROOT信息
    export GOROOT=/usr/local/go
    export PATH=$PATH:$GOROOT/bin
    export GOPATH=$HOME/go/
    export PATH=$PATH:$GOPATH/bin/
    
    // 添加完成后刷新环境变量
    source /etc/profile
    

    输入goenv查看当前golang的环境是否配置正确。

    安装Protocol Buffers v3

    先到github下载稳定版安装包wget https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protobuf-all-3.9.1.tar.gz

    // 解压
    tar xvf protobuf-all-3.9.1.tar.gz
    
    // 安装gcc c++
    参考:https://www.cnblogs.com/walkman-sky/p/9426775.html
    
    // 执行安装
    ./configure
    make && make install
    

    检查是否安装成功protoc --version

    安装grpc

    安装grpc有两种方法,最简单的是使用go get -u google.golang.org/grpc,但是此方法需要合理上网。

    第二种方法使用github安装

    cd $GOPATH/src
    mkdir google.golang.org
    cd google.golang.org/
    git clone https://github.com/grpc/grpc-go grpc
    

    安装Protoc Plugin

    安装Protoc Plugin使用go get -u github.com/golang/protobuf/protoc-gen-go

    安装grpc-gateway

    下载grpc-gateway主文件

    安装grpc-gateway同样有两种方法,go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway,直接使用go get 安装,此方法有一些依赖需要从google下载,所以需要合理上网。国内推荐使用第二种方法:

    cd $GOPATH/src/github.com
    mkdir grpc-ecosystem
    cd grpc-ecosystem
    git clone https://github.com/grpc-ecosystem/grpc-gateway.git
    

    编译安装yaml

    yaml是编译安装protoc-gen-grpc-gateway的必备文件

    cd $GOPATH/src/github.com
    mkdir ghodss
    cd ghodss
    git clone https://github.com/ghodss/yaml.git
    

    编译安装glog

    cd $GOPATH/src/github.com/golang
    git clone https://github.com/golang/glog.git
    

    安装yaml.v2

    go get gopkg.in/yaml.v2

    编译安装protoc-gen-grpc-gateway

    cd $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
    go build
    mv protoc-gen-grpc-gateway $GOPATH/bin
    

    编译安装protoc-gen-swagger

    cd $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
    go build
    mv protoc-gen-swagger $GOPATH/bin
    
  • 相关阅读:
    Start Developing iOS Apps (Swift) 开始开发iOS应用(Swift)
    ansible copy file
    多个sshkey 指定key来clone仓库
    elastic search 日期为string类型导致视图无法展示时间的解决办法
    ubuntu 安装php 报错解决
    ruby hash 默认值的问题
    11.Mysql 之MHA(高可用)
    10. 主从复制-主从复制(基于GTID)--附加半同步复制
    9 .mysql的备份与恢复
    11.Mysql之回表、最左匹配、索引下推
  • 原文地址:https://www.cnblogs.com/peilanluo/p/11357539.html
Copyright © 2011-2022 走看看