Go - Micro微服務框架實踐 - 新建模板(十八)

新建模板

micro new [service]

micro new命令是快速生成Micro服務代碼模板。

使用

創建新的服務,目錄會創建到$GOPATH的相對目錄。

micro new github.com/micro/foo

下面是常規操作的輸出

micro new github.com/micro/foo

creating service go.micro.srv.foo
creating /Users/asim/checkouts/src/github.com/micro/foo
creating /Users/asim/checkouts/src/github.com/micro/foo/main.go
creating /Users/asim/checkouts/src/github.com/micro/foo/handler
creating /Users/asim/checkouts/src/github.com/micro/foo/handler/example.go
creating /Users/asim/checkouts/src/github.com/micro/foo/subscriber
creating /Users/asim/checkouts/src/github.com/micro/foo/subscriber/example.go
creating /Users/asim/checkouts/src/github.com/micro/foo/proto/example
creating /Users/asim/checkouts/src/github.com/micro/foo/proto/example/example.proto
creating /Users/asim/checkouts/src/github.com/micro/foo/Dockerfile
creating /Users/asim/checkouts/src/github.com/micro/foo/README.md

download protobuf for micro:

go get github.com/micro/protobuf/{proto,protoc-gen-go}

compile the proto file example.proto:

protoc -I/Users/asim/checkouts/src \
    --go_out=plugins=micro:/Users/asim/checkouts/src \
    /Users/asim/checkouts/src/github.com/micro/foo/proto/example/example.proto

選項

對于一些特殊操作比如namespace, type, fqdn和alias:

micro new --fqdn com.example.srv.foo github.com/micro/foo

幫助信息

NAME:
   micro new - Create a new micro service

USAGE:
   micro new [command options] [arguments...]

OPTIONS:
   --namespace "go.micro"   Namespace for the service e.g com.example
   --type "srv"         Type of service e.g api, srv, web
   --fqdn           FQDN of service e.g com.example.srv.service (defaults to namespace.type.alias)
   --alias          Alias is the short name used as part of combined name if specified

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容