httputil

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrMissingFile = errors.New("httputil: no such file")

Functions

func GetFiles

func GetFiles(r *http.Request, key string) ([]*multipart.FileHeader, error)

GetFiles returns all the files for the provided form key.

func GetFormFile

func GetFormFile(r *http.Request, key string) (fileContent []byte, fileHeader *multipart.FileHeader, err error)

GetFormFile returns the first file content and header for the provided form key. GetFormfile uses FormFile function underneth so calls ParseMultipartForm and ParseForm if necessary

func GetFormValues

func GetFormValues(r *http.Request, key string) ([]string, error)

GetFormValues returns all the form values for the provided form key.

Types

type MediaType

type MediaType struct {
	Name   string
	Params map[string]string
}

MediaType represents a media type from an Accept header. Name property is the MIME type name (like "application/json"). Params property contains the media type option parameters.

func ParseMediaTypes

func ParseMediaTypes(accept string) []MediaType

ParseMediaTypes will parse one or multiple media type directives (i.e Accept or Content-Type headers) and return an array of MediaType representing the MIME type name and optional parameters.

Example
package main

import (
	"fmt"

	"github.com/ehsoc/rest/httputil"
)

func main() {
	accept := "application/json; indent=4, application/xml"
	result := httputil.ParseMediaTypes(accept)

	for _, mt := range result {
		fmt.Println(mt.Name, mt.Params)
	}
}
Output:

application/json map[indent:4]
application/xml map[]

Jump to

Keyboard shortcuts

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