request

package
v0.0.0-...-a839d2f Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IntBase int = 10
	BitSize int = 64
)

Variables

This section is empty.

Functions

func ExtractBody

func ExtractBody(request *Request, unmarshaler types.Unmarshaler, pointer interface{}, configs []Option) *response.AsObject

func ExtractParam

func ExtractParam(
	key string,
	paramPlacing placing.Placing,
	request *Request,
	configs []Option,
	convert func(string) (interface{}, error),
) *response.AsObject

ExtractParam - extracting parameter from context, calls middleware and saves to 'context.parameters[from][key]'. After this parameter can be retrieved from context using 'context.Query' methods.

func GetUnmarshaler

func GetUnmarshaler(request *Request) (types.Unmarshaler, error)

Types

type Middleware

type Middleware func(r *Request, w http.ResponseWriter) *response.AsObject

type Option

type Option func(*Parameter) error

type Parameter

type Parameter struct {
	Parsed interface{}

	Name        string
	Description string
	// contains filtered or unexported fields
}

type ParamsValidator

type ParamsValidator interface {
	Validate(param string) error
}

type Request

type Request struct {
	Description string
	// contains filtered or unexported fields
}

Request - provide methods for extracting r parameters from context.

func New

func New(request *http.Request) *Request

func (*Request) AddInPathParameter

func (r *Request) AddInPathParameter(key string, value string)

func (*Request) All

func (r *Request) All() map[placing.Placing]map[string]string

func (*Request) Body

func (r *Request) Body() interface{}

func (*Request) Bool

func (r *Request) Bool(key string, paramPlacing placing.Placing) bool

func (*Request) Float

func (r *Request) Float(key string, paramPlacing placing.Placing) float64

func (*Request) GetParameter

func (r *Request) GetParameter(key string, paramPlacing placing.Placing) string

func (*Request) GetRequest

func (r *Request) GetRequest() *http.Request

func (*Request) Headers

func (r *Request) Headers() map[string][]string

func (*Request) Integer

func (r *Request) Integer(key string, paramPlacing placing.Placing) int64

func (*Request) String

func (r *Request) String(key string, paramPlacing placing.Placing) string

func (*Request) Time

func (r *Request) Time(key, layout string, paramPlacing placing.Placing) time.Time

type Requester

type Requester interface {
	// Headers - returns request headers.
	Headers() map[string][]string
	// All - returns all parsed parameters.
	All() map[placing.Placing]map[string]string
	// GetParameter - returns parameter value from defined place.
	GetParameter(value string, place placing.Placing) string
	// GetRequest - return http.Request object associated with request.
	GetRequest() *http.Request
	// Body - returns request body.
	// Body must be requested by 'api.Body(pointer)' or 'api.CustomBody(unmarshaler, pointer)'.
	Body() interface{}
	// Bool - returns boolean parameter.
	// Mandatory parameter should be requested by 'api.Bool'.
	// Otherwise, parameter will be obtained by key and its value will be checked for truth.
	Bool(value string, place placing.Placing) bool
	// Integer - returns integer parameter.
	// Mandatory parameter should be requested by 'api.Integer'.
	// Otherwise, parameter will be obtained by key and its value will be converted. to int64.
	Integer(value string, place placing.Placing) int64
	// Float - returns floating point number parameter.
	// Mandatory parameter should be requested by 'api.Float'.
	// Otherwise, parameter will be obtained by key and its value will be converted to float64.
	Float(value string, place placing.Placing) float64
	// String - returns String parameter.
	// Mandatory parameter should be requested by 'api.String'.
	// Otherwise, parameter will be obtained by key.
	String(value string, place placing.Placing) string
	// Time - returns date-time parameter.
	// Mandatory parameter should be requested by 'api.Time'.
	// Otherwise, parameter will be obtained by key and its value will be converted to time using 'layout'.
	Time(key string, layout string, paramPlacing placing.Placing) time.Time
}

Jump to

Keyboard shortcuts

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