Home

Awesome

acceptlang wercker status

Using the acceptlang handler you can automatically parse the Accept-Language HTTP header and expose it as an AcceptLanguages slice in your handler functions. The AcceptLanguages slice contains AcceptLanguage values, each of which represent a qualified (or unqualified) language. The values in the slice are sorted descending by qualification (the most qualified languages will have the lowest indexes in the slice).

Unqualified languages are interpreted as having the maximum qualification of 1, as defined in the HTTP/1.1 specification.

For more information:

Usage

Simply add a new handler function instance to your handler chain using the acceptlang.Languages() function as well as an AcceptLanguages dependency in your handler function. The AcceptLanguages dependency will be satisified by the handler.

For example:

package main

import (
	"fmt"
	"github.com/go-martini/martini"
	"github.com/martini-contrib/acceptlang"
	"net/http"
)

func main() {
	m := martini.Classic()

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

	http.ListenAndServe(":8090", m)
}

Authors