go-micro 微服务开发中文手册
  • Introduction
  • 概述
    • 介绍
    • 微服务
    • 架构
    • 常见问题
    • 特性
    • 路标
    • 资源
    • 用户
  • 指南
    • 安装指南
    • gRPC网关
    • 编写一个Go服务
    • 编写一个Go函数
    • 容错
  • 组件
    • Go Micro
    • API
    • Web
    • Sidecar
    • CLI
    • Bot
    • New
    • Run
  • 部署
    • Docker
    • Kubernetes
  • 插件
    • 概述
    • Go Micro
    • 工具包
    • NATS
Powered by GitBook
On this page
  • 用法
  • 选项
  • 帮助

Was this helpful?

  1. 组件

New

micro new命令是为微服务生成示例模板的快捷方式。

用法

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

Last updated 5 years ago

Was this helpful?