req

package
v0.0.0-...-9d8ded8 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package req provides a convenient wrapper around http.Request.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoCookie = errors.New("no cookie")
	ErrNoFile   = errors.New("no file")
	ErrNoForm   = errors.New("no form")
	ErrNoHeader = errors.New("no header")
	ErrNoQuery  = errors.New("no query")
)

Functions

func Context

func Context(r *http.Request) context.Context

Context returns the request's context.

func Cookie(r *http.Request, name string) (*http.Cookie, error)

Cookie returns the named cookie provided in the request or ErrNoCookie if not found. If multiple cookies match the given name, only one cookie will be returned.

func Cookies

func Cookies(r *http.Request) []*http.Cookie

Cookies parses and returns the HTTP cookies sent with the request.

func File

func File(r *http.Request, a any) error

File parses multipart form returns the first file associated with the `file` key. Filename (*string) and File ([]byte) fields are used to store file name and data.

func FileValue

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

FileValue parses multipart form returns the first file associated with the given key.

func Form

func Form(r *http.Request, a any) error

Form parses the raw query from the url.URL and decodes it to a struct. The tag `req` is used to locate custom field aliases.

func FormValue

func FormValue(r *http.Request, key string) (string, error)

FormValue returns the first value for the named component of the POST, PUT, or PATCH request body.

func Header(r *http.Request, key string) (string, error)

Header returns the first value associated with the given key. If there are no values associated with the key, Header returns "".

func Headers

func Headers(r *http.Request) http.Header

Headers returns the request header fields either received by the server.

func ID

func ID(r *http.Request) int

ID return the `id` url parameter form a http.Request.

func Json

func Json(r *http.Request, a any) error

Json reads the JSON-encoded body and stores it in the value pointed to by v.

func Query

func Query(r *http.Request, a any) error

Query parses url.RawQuery and decodes the corresponding values to a struct. The tag `query` is used to locate custom field aliases.

func QueryValue

func QueryValue(r *http.Request, key string) (string, error)

QueryValue parses url.RawQuery and returns the first value associated with the given key. If there are no values associated with the key, QueryValue returns the empty string.

func Session

func Session(r *http.Request) (*session.Session, error)

Session returns the request's session.

func Var

func Var(r *http.Request, key string) string

Var returns the url parameter from a http.Request.

func Vars

func Vars(r *http.Request) map[string]string

Vars returns all url parameters form a http.Request.

Types

This section is empty.

Jump to

Keyboard shortcuts

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