当前位置:网站首页>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"
边栏推荐
- Hologres shared cluster helps Taobao subscribe to the extreme refined operation
- Mathematical modeling for war preparation 34-bp neural network prediction 2
- 利用PIL进行不失真的resize
- mysql8报错:ERROR 1410 (42000): You are not allowed to create a user with GRANT解决办法
- Build cloud native observability capability suitable for organizations
- Niuke: how many different binary search trees are there
- IO流_递归
- Additional: (not written yet, don't look at ~ ~ ~) corsfilter filter;
- 声网自研传输层协议 AUT 的落地实践丨Dev for Dev 专栏
- Two methods for MySQL to open remote connection permission
猜你喜欢

IO流_递归
Mysql8.0 method and steps for enabling remote connection permission

容联云首发基于统信UOS的Rphone,打造国产化联络中心新生态

BC1.2 PD协议

Etcd教程 — 第八章 Etcd之Compact、Watch和Lease API

备战数学建模34-BP神经网络预测2

牛客网:乘积为正数的最长连续子数组

【Verilog基础】关于Clock信号的一些概念总结(clock setup/hold、clock tree、clock skew、clock latency、clock transition..)

Etcd教程 — 第九章 Etcd之实现分布式锁

RT-Thread 堆区大小设置
随机推荐
利用PIL进行不失真的resize
备战数学建模33-灰色预测模型2
Niuke network: longest continuous subarray with positive product
腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?
Additional: (not written yet, don't look at ~ ~ ~) corsfilter filter;
Mathematical modeling for war preparation 34-bp neural network prediction 2
Half year inventory of new consumption in 2022: the industry is cold, but these nine tracks still attract gold
Home office discussion on the experience of remote assistance to quickly improve efficiency | community essay solicitation
Explain in detail the use of for loop, break and continue in go language
更多龙蜥自研特性!生产可用的 Anolis OS 8.6 正式发布
RTP 发送PS流零拷贝方案
云和恩墨中标天津滨海农村商业银行2022-2023年度Oracle维保项目
TCP Socket与TCP 连接
[Verilog basics] octal and hexadecimal representation of decimal negative numbers
BC1.2 PD协议
Lambda表达式_Stream流_File类
POJ Project Summer
KDD 2022 | how far are we from the general pre training recommendation model? Universal sequence representation learning model unisrec for recommender system
Headhunter 50, 000, I'll go to VC
荣盛生物冲刺科创板:拟募资12.5亿 年营收2.6亿