httplib

package
v2.2.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package httplib implements common utility functions for writing classic HTTP handlers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertResponse

func ConvertResponse(re *roundtrip.Response, err error) (*roundtrip.Response, error)

ConvertResponse converts http error to internal error type based on HTTP response code and HTTP body contents

func InsecureSetDevmodeHeaders

func InsecureSetDevmodeHeaders(w http.ResponseWriter)

InsecureSetDevmodeHeaders allows cross-origin requests, used in dev mode only

func MakeHandler

func MakeHandler(fn HandlerFunc) httprouter.Handle

MakeHandler returns a new httprouter.Handle func from a handler func

func MakeStdHandler

func MakeStdHandler(fn StdHandlerFunc) http.HandlerFunc

MakeStdHandler returns a new http.Handle func from http.HandlerFunc

func ParseBool

func ParseBool(q url.Values, name string) (bool, bool, error)

ParseBool will parse boolean variable from url query returns value, ok, error

func ReadJSON

func ReadJSON(r *http.Request, val interface{}) error

ReadJSON reads HTTP json request and unmarshals it into passed interface{} obj

func RewritePaths

func RewritePaths(next http.Handler, rewrites ...RewritePair) http.Handler

RewritePaths creates a middleware that rewrites paths in incoming request

Types

type HandlerFunc

type HandlerFunc func(w http.ResponseWriter, r *http.Request, p httprouter.Params) (interface{}, error)

HandlerFunc specifies HTTP handler function that returns error

type RewritePair

type RewritePair struct {
	// Expr is matching expression
	Expr *regexp.Regexp
	// Replacement is replacement
	Replacement string
}

RewritePair is a rewrite expression

func Rewrite

func Rewrite(in, out string) RewritePair

Rewrite creates a rewrite pair, panics if in epxression is not a valid regular expressoin

type StdHandlerFunc

type StdHandlerFunc func(w http.ResponseWriter, r *http.Request) (interface{}, error)

StdHandlerFunc specifies HTTP handler function that returns error

Jump to

Keyboard shortcuts

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