当前位置:网站首页>Go micro tutorial - Chapter 1 getting started
Go micro tutorial - Chapter 1 getting started
2022-06-30 16:50:00 【Ximu Qi】
go-micro course — Chapter one Quick start
One 、 The required depend on
go-micro
need protoc-gen-micro
To generate code . So we need to rely on :
- protobuf
- protoc-gen-go
- protoc-gen-micro
Download the latest version of dependencies
go get https://github.com/protocolbuffers/protobuf/releases
go get github.com/golang/protobuf/protoc-gen-go
go get github.com/micro/micro/v3/cmd/protoc-gen-micro
Two 、 install micro
The latest version of micro yes 3.0 Version of , So here we install 3.0 Version of micro.
2.1 Go Get Way to install :
go install github.com/micro/micro/[email protected]
2.2 Binary version
# MacOS
curl -fsSL https://raw.githubusercontent.com/micro/micro/master/scripts/install.sh | /bin/bash
# Linux
wget -q https://raw.githubusercontent.com/micro/micro/master/scripts/install.sh -O - | /bin/bash
# Windows
powershell -Command "iwr -useb https://raw.githubusercontent.com/micro/micro/master/scripts/install.ps1 | iex"
2.3 Docker Mirror image
docker pull micro/micro
3、 ... and 、 function micro service
Before you start writing services , Let's run an existing service , Because it only needs a few commands !
3.1 start-up micro server service
First , We have to start micro server
. The command to do this is :
micro server
3.2 Sign in
In the use of micro server
You need to log in to the service before , The default account and password are as follows :
account number / password :admin/micro
E:\Goland\go-micro-demo>micro login
Enter username: admin
Enter password:
Successfully logged in.
see micro server
Services running in , command :
E:\Goland\go-micro-demo>micro services
api
auth
broker
config
events
network
proxy
registry
runtime
store
web
altogether 11 individual , All these services are micro server Sub modules in , View on the browser side localhost:8082
.
This is cool , But it's still not what we're rolling out ! Let's start a service , We can really believe in its existence . If we go github.com/micro/services, We'll see a bunch of services written by micro authors . One of them is helloworld.
3.3 function helloworld
The command to run the service is micro run
.
micro run github.com/micro/services/helloworld
View the status of the running service :
E:\Goland\go-micro-demo>micro status
NAME VERSION SOURCE STATUS BUILD UPDATED METADATA
helloworld latest github.com/micro/services/helloworld running n/a 4s ago owner=admin, group=micro
We can also check the log of the service to verify that it is running :
E:\Goland\go-micro-demo>micro logs helloworld
2022-6-06 17:52:21 file=service/service.go:195 level=info Starting [service] helloworld
2022-6-06 17:52:21 file=grpc/grpc.go:902 level=info Server [grpc] Listening on [::]:33975
2022-6-06 17:52:21 file=grpc/grpc.go:732 level=info Registry [service] Registering node: helloworld-67627b23-3336-4b92-a032-09d8d13ecf95
Four 、 Call the service
Micro Automatically generate... For your service CLI command , The format is :micro [service] [method]
, The default method is “ call ”. Parameters can be passed as flags , So we can call our service in the following ways :
$ micro helloworld call --name=Jane
{
"msg": "Hello Jane"
}
If we want to know which nodes the service has , We can run the following command :
E:\Goland\go-micro-demo>micro helloworld --help
NAME:
micro helloworld
VERSION:
latest
USAGE:
micro helloworld [command]
COMMANDS:
call
Use API Way to call :
Micro stay 8080 A port is open http API, So you can use curl
Way to call .
curl "http://localhost:8080/helloworld?name=John"
边栏推荐
- 云技能提升好伙伴,亚马逊云师兄今天正式营业
- There are so many kinds of coupons. First distinguish them clearly and then collect the wool!
- MySQL8.0开启远程连接权限的方法步骤
- Wechat emoticons are written into the judgment, and the OK and bomb you send may become "testimony in court"
- 牛客网:乘积为正数的最长连续子数组
- Mathematical modeling for war preparation 35 time series prediction model
- Cesium-1.72 learning (earth model creation online offline tile)
- Niuke.com: minimum cost of climbing stairs
- Go zero micro Service Practice Series (VIII. How to handle tens of thousands of order requests per second)
- MicroBlaze serial port learning · 2
猜你喜欢
mysql8报错:ERROR 1410 (42000): You are not allowed to create a user with GRANT解决办法
How cloudxr promotes the future development of XR
24:第三章:开发通行证服务:7:自定义异常(来表征程序中出现的错误);创建GraceExceptionHandler来全局统一处理异常(根据异常信息,构建对应的API统一返回对象的,JSON数据);
Etcd教程 — 第九章 Etcd之实现分布式锁
The inspiration from infant cognitive learning may be the key to the next generation of unsupervised machine learning
安全帽佩戴检测算法研究
OpenCV中LineTypes各枚举值(LINE_4 、LINE_8 、LINE_AA )的含义
KDD 2022 | how far are we from the general pre training recommendation model? Universal sequence representation learning model unisrec for recommender system
15年做糊21款硬件,谷歌到底栽在哪儿?
MC Instruction Decoder
随机推荐
register_chrdev和cdev_init cdev_add用法区别
快照和备份
Home office discussion on the experience of remote assistance to quickly improve efficiency | community essay solicitation
Etcd教程 — 第八章 Etcd之Compact、Watch和Lease API
STL教程7-set、pair对组和仿函数
Delete duplicates in an ordered array ii[double pointers -- unified in multiple cases]
KDD 2022 | how far are we from the general pre training recommendation model? Universal sequence representation learning model unisrec for recommender system
深度学习——(2)几种常见的损失函数
15年做糊21款硬件,谷歌到底栽在哪儿?
[activity registration] it's your turn to explore the yuan universe! I will be waiting for you in Shenzhen on July 2!
Mathematical modeling for war preparation 33- grey prediction model 2
19:00 p.m. tonight, knowledge empowerment phase 2 live broadcast - control panel interface design of openharmony smart home project
Mysql8 error: error 1410 (42000): you are not allowed to create a user with grant solution
go-micro教程 — 第一章 快速入门
I 用c I 实现“栈”
牛客网:乘积为正数的最长连续子数组
Etcd教程 — 第八章 Etcd之Compact、Watch和Lease API
附加:(还没写,别看~~~)WebMvcConfigurer接口;
详解Go语言中for循环,break和continue的使用
牛客网:最小花费爬楼梯