meta

command
v0.0.0-...-908d554 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.example的Example.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.example的Foo.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