request

package
v0.0.0-...-84d4900 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLang = "en"

DefaultLang is the default language. Need to be setted in the starup of the application.

Functions

func Handler

func Handler(rc *Config, formsizefile int64, handler http.HandlerFunc) http.HandlerFunc

Handler reads the information in the request parameter and process it, the result got to the context under the name "request". All data from the request must be accessed with the function Request(r), i.e. Request(r).Referrer(). This is done with the intent of make the information in r more acessible and in this way avaid repetitive work.

Types

type Config

type Config struct {
	AcceptedUserAgents *useragent.UAVers
	AcceptedLanguages  []string
	AcceptedEncoding   []string
	AcceptedMedias     []string
	AcceptedCharsets   []string
	Localhosts         []string
}

Config is the configuration for the request parse and pre processing.

var DefaultConfig *Config

DefaultRequestConfig is a simple default config for request.

type UserRequest

type UserRequest struct {
	// contains filtered or unexported fields
}

UserRequest provide methods to access the user request information.

func Request

func Request(r *http.Request) *UserRequest

Request get the user request from the context.

func (*UserRequest) Charset

func (ur *UserRequest) Charset() string

Charset return the accepted charset by the user.

func (*UserRequest) Encoding

func (ur *UserRequest) Encoding() string

Encoding return the encoding algorithm accepted by the user.

func (*UserRequest) IP

func (ur *UserRequest) IP() string

IP returns the users real ip.

func (*UserRequest) IsLocalhost

func (ur *UserRequest) IsLocalhost() bool

IsLocalhost is local host.

func (*UserRequest) LangDir

func (ur *UserRequest) LangDir() string

LangDir is the language write direction, always return ltr.

func (*UserRequest) Language

func (ur *UserRequest) Language() string

Language return the language accepted by the user.

func (*UserRequest) Media

func (ur *UserRequest) Media() string

Media return the accepted media by the user.

func (*UserRequest) Query

func (ur *UserRequest) Query() map[string]string

Query returns a map with the queries in the url made by the user.

func (*UserRequest) Referrer

func (ur *UserRequest) Referrer() *url.URL

Referrer return the referrer url.

func (*UserRequest) Timezone

func (ur *UserRequest) Timezone() *time.Location

Timezone receives the time zone from que query parameter tz in the javascript format and convert it to time.Location.

func (*UserRequest) URL

func (ur *UserRequest) URL() *url.URL

URL return the user requested url.

func (*UserRequest) Useragent

func (ur *UserRequest) Useragent() *useragent.Product

Useragent return the user ua.

Jump to

Keyboard shortcuts

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