httpx

package
v0.0.0-...-2eec6a9 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2017 License: LGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package httpx helper functions for http operations

Index

Constants

View Source
const (
	JSONContentType        = "application/json; charset=utf-8"
	OctetStreamContentType = "application/octet-stream"
)

content types

Variables

This section is empty.

Functions

func Error

func Error(err error, status int) error

Error create an error with http status code.

func HandleResponseError

func HandleResponseError(resp *http.Response) error

HandleResponseError check response status code. If code is not 2xx, then error returned.

func IsCausedByContextCanceled

func IsCausedByContextCanceled(err error) bool

IsCausedByContextCanceled to check if the err

func ResponseJSON

func ResponseJSON(w http.ResponseWriter, obj interface{}) error

ResponseJSON reponse a object in JSON enconding

func WrapHandlerFunc

func WrapHandlerFunc(f HandlerFunc) http.HandlerFunc

WrapHandlerFunc convert HandlerFunc to http.HandlerFunc

Types

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request) error

HandlerFunc like http.HandlerFunc, bu it returns an error. If the returned error is errorWithStatus type, errorWithStatus.status will be responded, otherwise http.StatusInternalServerError responded.

Jump to

Keyboard shortcuts

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