http

package module
v0.0.0-...-59d77f7 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

README

HTTP Client

This plugin is a http client for micro.

Overview

The http client wraps net/http to provide a robust micro client with service discovery, load balancing and streaming. It complies with the micro.Client interface.

Usage

Use directly
import "github.com/unistack-org/micro-client-http"

service := micro.NewService(
	micro.Name("my.service"),
	micro.Client(http.NewClient()),
)
Call Service

Assuming you have a http service "my.service" with path "/foo/bar"

// new client
client := http.NewClient()

// create request/response
request := client.NewRequest("my.service", "/foo/bar", protoRequest{})
response := new(protoResponse)

// call service
err := client.Call(context.TODO(), request, response)

or you can call any rest api or site and unmarshal to response struct

// new client
client := client.NewClientCallOptions(http.NewClient(), http.Address("https://api.github.com"))

req := client.NewRequest("github", "/users/vtolstov", nil)
rsp := make(map[string]interface{})

err := c.Call(context.TODO(), req, &rsp, mhttp.Method(http.MethodGet)) 

Look at http_test.go for detailed use.

Encoding

Default protobuf with content-type application/proto

client.NewRequest("service", "/path", protoRequest{})

Json with content-type application/json

client.NewJsonRequest("service", "/path", jsonRequest{})

Documentation

Overview

Package http provides a http client

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultPoolMaxStreams maximum streams on a connectioin
	// (20)
	DefaultPoolMaxStreams = 20

	// DefaultPoolMaxIdle maximum idle conns of a pool
	// (50)
	DefaultPoolMaxIdle = 50

	// DefaultMaxRecvMsgSize maximum message that client can receive
	// (4 MB).
	DefaultMaxRecvMsgSize = 1024 * 1024 * 4

	// DefaultMaxSendMsgSize maximum message that client can send
	// (4 MB).
	DefaultMaxSendMsgSize = 1024 * 1024 * 4
)

Functions

func AuthTLS

func AuthTLS(t *tls.Config) client.Option

AuthTLS should be used to setup a secure authentication using TLS

func ErrorMap

func ErrorMap(m map[string]interface{}) client.CallOption

func HTTPClient

func HTTPClient(c *http.Client) client.Option

func HTTPDialer

func HTTPDialer(d *net.Dialer) client.Option

func MaxRecvMsgSize

func MaxRecvMsgSize(s int) client.Option

MaxRecvMsgSize set the maximum size of message that client can receive.

func MaxSendMsgSize

func MaxSendMsgSize(s int) client.Option

MaxSendMsgSize set the maximum size of message that client can send.

func Method

func Method(m string) client.CallOption

func NewClient

func NewClient(opts ...client.Option) client.Client

func Path

func Path(p string) client.CallOption

func PoolMaxIdle

func PoolMaxIdle(d int) client.Option

maximum idle conns of a pool

func PoolMaxStreams

func PoolMaxStreams(n int) client.Option

maximum streams on a connectioin

Types

This section is empty.

Jump to

Keyboard shortcuts

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