新项目模板

未匹配的标注
本文档最新版为 3.x,旧版本可能放弃维护,推荐阅读最新版!

新项目模板

micro new [service]

*micro new * 命令是生成 micro services 样板模板的便捷方法.

使用

通过指定相对于 $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

选项

也可以指定更多选项, 如命名空间, 类型, fqdn 和别名

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

本文章首发在 LearnKu.com 网站上。

上一篇 下一篇
taadis
讨论数量: 0
发起讨论 只看当前版本


暂无话题~