9

go-micro微服务教程一:搭建go-micro运行环境

 2 years ago
source link: http://entere.github.io/2019/10/29/go-micro%E5%BE%AE%E6%9C%8D%E5%8A%A1%E6%95%99%E7%A8%8B%E4%B8%80%EF%BC%9A%E6%90%AD%E5%BB%BAgo-micro%E8%BF%90%E8%A1%8C%E7%8E%AF%E5%A2%83/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

go-micro微服务教程一:搭建go-micro运行环境

本章节的目的是让大家最快速搭建好 go-micro 运行环境 获取本节代码

go-micro是基于 Go语言实现的插件化 RPC 微服务框架,与go-kit,kite等微服务框架相比,它具有易上手、部署简单、工具插件化等优点。

名称 说明
OS macOS Mojave 10.14.6
Golang go1.13 darwin/amd64
Micro micro version 1.11.3
G111MODULE on

安装 micro 工具包

micro提供了一系列的工具来帮助我们更好的使用 go-micro。,如果没有安装 golang 请先安装 golang
如果安装方式一出错,提示包找不到可以用安装方式二

# 安装方式一
go get -u -v github.com/micro/micro
cd $GOPATH/src/github.com/micro/micro
go build -o micro main.go
sudo cp micro /usr/local/bin/

# 安装方式二

cd $GOPATH/src/github.com/micro/
git clone https://github.com/micro/micro.git
cd $GOPATH/src/github.com/micro/micro
go build -o micro main.go
sudo cp micro /usr/local/bin/

安装框架go-micro

go get -u -v github.com/micro/go-micro

安装 protoc

官方地址

# 源码安装,下载最新版,目前是 v3.10.1

wget https://github.com/protocolbuffers/protobuf/releases/download/v3.10.1/protobuf-all-3.10.1.tar.gz
tar zxvf protobuf-all-3.10.1.tar.gz
cd protobuf-3.10.1/
./autogen.sh
./configure
make
make install
protoc -h

# 或者
git clone https://github.com/google/protobuf
cd protobuf
./autogen.sh
./configure
make
make check
sudo make install

安装 Go 版本的 protobuf 编译器 protoc-gen-go

go get -u -v github.com/golang/protobuf/protoc-gen-go

在 github 上创建 micro-examples 项目

在开始之前,我们先在github上创建 micro-examples 项目,并使用 go mod init 初始化生成go.mod 文件,我们用 Go Modules 管理 Go 模块依赖

cd micro-examples
go mod init github.com/entere/micro-examples

配置 Go IDE goland

我们用 goland 开发go应用

去掉”Use GOPATH that’s defined in system environment”前面的√
选中Enable Go Modules(vgo) intergration,并在proxy中输入 https://goproxy.io

下一节,我们将会创建一个简单的微服务go-micro微服务教程二:创建微服务


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK