Back to godoc.org
github.com/martini-contrib/acceptlang

package acceptlang

v0.0.0 (4f60163)
Latest Go to latest
Published: Mar 31, 2014 | License: MIT | Module: github.com/martini-contrib/acceptlang

Overview

Package acceptlang provides a Martini handler and primitives to parse the Accept-Language HTTP header values.

See the HTTP header fields specification for more details (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4).

Example

Use the handler to automatically parse the Accept-Language header and return the results as response:

m.Get("/", acceptlang.Languages(), func(languages acceptlang.AcceptLanguages) string {
    return fmt.Sprintf("Languages: %s", languages)
})

Index

func Languages

func Languages() martini.Handler

Creates a new handler that parses the Accept-Language HTTP header.

The parsed structure is a slice of Accept-Language values stored in an AcceptLanguages instance, sorted based on the language qualifier.

type AcceptLanguage

type AcceptLanguage struct {
	Language string
	Quality  float32
}

A single language from the Accept-Language HTTP header.

type AcceptLanguages

type AcceptLanguages []AcceptLanguage

A slice of sortable AcceptLanguage instances.

func (AcceptLanguages) Len

func (al AcceptLanguages) Len() int

Returns the total number of items in the slice. Implemented to satisfy sort.Interface.

func (AcceptLanguages) Less

func (al AcceptLanguages) Less(i, j int) bool

Determines whether or not the item at position i is "less than" the item at position j. Implemented to satisfy sort.Interface.

func (AcceptLanguages) String

func (al AcceptLanguages) String() string

Returns the parsed languages in a human readable fashion.

func (AcceptLanguages) Swap

func (al AcceptLanguages) Swap(i, j int)

Swaps the items at position i and j. Implemented to satisfy sort.Interface.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier