http

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package http provide go-kit http transport functions.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeJSONResponse

func EncodeJSONResponse(ctx context.Context, w http.ResponseWriter, response interface{}) error

EncodeJSONResponse is a EncodeResponseFunc that serializes the response as a JSON object to the ResponseWriter. Its works like standard go-lit EncodeJSONResponse but checks Failer and RawResponder interfaces

func MakeJSONRequestDecoder

func MakeJSONRequestDecoder(requestFactory func() interface{}) kithttp.DecodeRequestFunc

MakeJSONRequestDecoder is the universal DecodeRequestFunc creator

Example
kithttp.NewServer(
	makeSomeEndpoint(),
	MakeJSONRequestDecoder(func() interface{} { return &someRequest{} }),
	kithttp.EncodeJSONResponse,
)
Output:

func RecoveringMiddleware

func RecoveringMiddleware(handler http.Handler, errorEncoder kithttp.ErrorEncoder) http.Handler

RecoveringMiddleware recovers panic and returns error to client

Example
var handler http.Handler
{
	handler = kithttp.NewServer(
		makeSomeEndpoint(),
		MakeJSONRequestDecoder(func() interface{} { return &someRequest{} }),
		kithttp.EncodeJSONResponse,
	)
	handler = RecoveringMiddleware(handler, kithttp.DefaultErrorEncoder)
}

// do something with handler
handler.ServeHTTP(responseWriter, request)
Output:

Types

type RawResponder

type RawResponder interface {
	RawResponse() io.Reader
}

RawResponder is checked by EncodeJSONResponse. It should return io.Reader to copy it to http.ResponseWriter

Jump to

Keyboard shortcuts

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