meta

command
v0.0.0-...-fabbfc5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

Meta API

本篇演示如何使用metadata模式下的Micro API,以下简称API。go-micro支持将请求路由到服务元数据声明的方法,也即是基于元数据的服务发现。

使用方法

使用protoc生成go代码

protoc --go_out=. --micro_out=. proto/api.proto

运行API网关,可以看到,API启动时,并没有声明handler模式,故而使用的RPC模式。所以Meta API其实是在RPC模式的基础上,通过在接口层声明端点元数据而指定服务的。

micro api

运行示例程序,在代码中注册服务时,我们在endpoint参数中写入了元数据,声明接口为 /example/foo/bar

go run meta.go

/example POST请求时,会被转到go.micro.api.exampleExample.Call方法。

curl -H 'Content-Type: application/json' -d '{"name": "john"}' "http://localhost:8080/example"
curl -XGET "http://localhost:8080/example?name=john"

/foo/bar POST请求时,会被转到go.micro.api.exampleFoo.Bar方法。

curl -H 'Content-Type: application/json' -d '{}' http://localhost:8080/foo/bar
curl -XGET "http://localhost:8080/foo/bar"
curl -XDELETE "http://localhost:8080/foo/bar"

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL