bodyparser

package module
v0.0.0-...-32e7e37 Latest Latest
Warning

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

Go to latest
Published: May 6, 2017 License: MIT Imports: 7 Imported by: 0

README

bodyparser

Build Status Go Report Card

Automatically parse the net/http request.Body into request.Form data depending on the Content-Type header.

Example

func main() {
	h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		body := fmt.Sprintf("Hello %s!", r.FormValue("name"))
		w.Write([]byte(body))
	})

	handler := bodyparser.Middleware(h)
	http.ListenAndServe(":3000", handler)
}

API

func Middleware(h http.Handler) http.Handler

A middleware for net/http to parse request bodies into request.Form data depending on the content type.

func Parse(r *http.Request) (map[string]interface{}, error)

Similar to Middleware, but instead of fitting the data into request.Form, returns a map[string]interface{}. Useful for parsing more complex data than string to string.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(h http.Handler) http.Handler

Middleware is a net/http middleware function for parsing the request body into Form and PostForm.

func Parse

func Parse(r *http.Request) (map[string]interface{}, error)

Parse parses the request body depending on the content-type header.

Types

This section is empty.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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