rpc

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: 5 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

RPC API

本示例我们介绍如何使用RPC handler模式的Micro API,以下简称API。

该模式下允许我们通过RPC的方式把HTTP请求转发到go-micro微服务上。

需要提醒的是,RPC模式下API只接收POST方式的请求,并且只消费(consume)内容格式content-type为application/json或者application/protobuf。

使用方法

使用protoc生成go代码

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

以rpc模式运行API

micro api --handler=rpc --namespace=go.micro.rpc
go run rpc.go

当我们POST请求到 /example/call时,API会将它转成RPC转发到go.micro.rpc.example服务的Example.Call接口上。

curl -H 'Content-Type: application/json' -d '{"name": "小小先"}' "http://localhost:8080/example/call"

同样,POST请求到 /example/foo/bar时,API会将它转成RPC转发到go.micro.api.example服务的Foo.Bar接口上。

curl -H 'Content-Type: application/json' -d '{}' http://localhost:8080/example/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