CLI
micro cli
micro cli是一個類命令行接口的工具,micro。
安裝
go get github.com/micro/micro
交互模式
CLI有帶提示的交互模式:
micro cli
如果是在交互模式中時,下面的指令中的micro
要刪掉,非交互模式即直接命令行執行才需要。
使用示例
列出服務
micro list services
獲取服務
micro get service go.micro.srv.example
輸出:
go.micro.srv.example
go.micro.srv.example-fccbb6fb-0301-11e5-9f1f-68a86d0d36b6 [::] 62421
調用服務
micro call go.micro.srv.example Example.Call '{"name": "John"}'
輸出:
{
"msg": "go.micro.srv.example-fccbb6fb-0301-11e5-9f1f-68a86d0d36b6: Hello John"
}
服務健康檢測
micro health go.micro.srv.example
輸出
node address:port status
go.micro.srv.example-fccbb6fb-0301-11e5-9f1f-68a86d0d36b6 [::]:62421 ok
注冊/卸載服務
micro register service '{"name": "foo", "version": "bar", "nodes": [{"id": "foo-1", "address": "127.0.0.1", "port": 8080}]}'
micro deregister service '{"name": "foo", "version": "bar", "nodes": [{"id": "foo-1", "address": "127.0.0.1", "port": 8080}]}'
代理遠程環境
代理遠程的環境,可以使用micro proxy
如果針對遠程環境進行開發時,可能無法直接訪問服務,這使用CLI操作變更很不方便。micro proxy
提供了http代理解決這種使用場景。
在遠程環境中運行,啟動代理
micro proxy
在命令行中帶上MICRO_PROXY_ADDRESS
遠程代理的地址,這樣客戶端的CLI就知道要連上這個代理
MICRO_PROXY_ADDRESS=staging.micro.mu:8081 micro list services
使用方式
NAME:
micro - A cloud-native toolkit
USAGE:
micro [global options] command [command options] [arguments...]
VERSION:
0.8.0
COMMANDS:
api Run the micro API
bot Run the micro bot
registry Query registry
call Call a service or function
query Deprecated: Use call instead
stream Create a service or function stream
health Query the health of a service
stats Query the stats of a service
list List items in registry
register Register an item in the registry
deregister Deregister an item in the registry
get Get item from registry
proxy Run the micro proxy
new Create a new micro service by specifying a directory path relative to your $GOPATH
web Run the micro web app