request

package
v0.0.0-...-89e9927 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package request provides utilities for binding, validating, and processing HTTP request data

Package request provides utilities for binding and validating HTTP request data

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindAll

func BindAll(r *http.Request, params map[string]string, obj interface{}) error

BindAll binds data from multiple sources to a struct

func BindForm

func BindForm(r *http.Request, obj interface{}) error

BindForm binds form data to a struct

func BindHeader

func BindHeader(r *http.Request, obj interface{}) error

BindHeader binds HTTP headers to a struct

func BindJSON

func BindJSON(r *http.Request, obj interface{}) error

BindJSON binds the request body to a struct using JSON

func BindPath

func BindPath(params map[string]string, obj interface{}) error

BindPath binds URL path parameters to a struct

func BindQuery

func BindQuery(r *http.Request, obj interface{}) error

BindQuery binds query parameters to a struct

func BindXML

func BindXML(r *http.Request, obj interface{}) error

BindXML binds the request body to a struct using XML

func BindYAML

func BindYAML(r *http.Request, obj interface{}) error

BindYAML binds the request body to a struct using YAML

func GetContentType

func GetContentType(r *http.Request) string

GetContentType returns the content type of the request

func IsForm

func IsForm(r *http.Request) bool

IsForm checks if the request content type is form data

func IsJSON

func IsJSON(r *http.Request) bool

IsJSON checks if the request content type is JSON

func IsXML

func IsXML(r *http.Request) bool

IsXML checks if the request content type is XML

func IsYAML

func IsYAML(r *http.Request) bool

IsYAML checks if the request content type is YAML

func SmartBind

func SmartBind(r *http.Request, obj interface{}) error

SmartBind automatically detects content type and binds accordingly

func Validate

func Validate(obj interface{}) error

Validate validates a struct based on validation tags

Types

type Auth

type Auth struct {
	Type     string                 // "bearer", "basic", "api-key", "jwt", "oauth", "custom"
	Token    string                 // The actual token/credential
	Username string                 // For basic auth
	Password string                 // For basic auth
	Claims   map[string]interface{} // For JWT/custom claims
	Valid    bool                   // Whether the auth is valid
	Metadata map[string]string      // Additional auth metadata
}

Auth provides comprehensive authentication information

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

Request wraps http.Request with additional functionality

func New

func New(r *http.Request) *Request

New creates a new Request wrapper

func (*Request) Accept

func (r *Request) Accept() string

Accept returns the Accept header

func (*Request) AcceptEncoding

func (r *Request) AcceptEncoding() string

AcceptEncoding returns the Accept-Encoding header

func (*Request) AcceptLanguage

func (r *Request) AcceptLanguage() string

AcceptLanguage returns the Accept-Language header

func (*Request) AcceptsHTML

func (r *Request) AcceptsHTML() bool

AcceptsHTML checks if the client accepts HTML responses

func (*Request) AcceptsJSON

func (r *Request) AcceptsJSON() bool

AcceptsJSON checks if the client accepts JSON responses

func (*Request) AcceptsPlainText

func (r *Request) AcceptsPlainText() bool

AcceptsPlainText checks if the client accepts plain text responses

func (*Request) AcceptsXML

func (r *Request) AcceptsXML() bool

AcceptsXML checks if the client accepts XML responses

func (*Request) AcceptsYAML

func (r *Request) AcceptsYAML() bool

AcceptsYAML checks if the client accepts YAML responses

func (*Request) AuthToken

func (r *Request) AuthToken() string

AuthToken returns the authentication token

func (*Request) AuthType

func (r *Request) AuthType() string

AuthType returns the authentication type

func (*Request) Authorization

func (r *Request) Authorization() string

Authorization returns the Authorization header

func (*Request) BaseURL

func (r *Request) BaseURL() string

BaseURL returns the base URL of the request

func (*Request) BearerToken

func (r *Request) BearerToken() string

BearerToken extracts Bearer token from Authorization header

func (*Request) Body

func (r *Request) Body() ([]byte, error)

Body returns the request body as bytes

func (*Request) ClientIP

func (r *Request) ClientIP() string

ClientIP returns the client's IP address

func (*Request) ContentLength

func (r *Request) ContentLength() int64

ContentLength returns the content length

func (*Request) ContentType

func (r *Request) ContentType() string

ContentType returns the content type

func (*Request) Cookie

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

Cookie returns a cookie value

func (*Request) CookieValue

func (r *Request) CookieValue(name string) (string, error)

CookieValue returns a cookie value as string

func (*Request) CookieValueDefault

func (r *Request) CookieValueDefault(name, defaultValue string) string

CookieValueDefault returns a cookie value or default

func (*Request) FileHeader

func (r *Request) FileHeader(key string) (*multipart.FileHeader, error)

FileHeader returns the file header for a multipart form file

func (*Request) Files

func (r *Request) Files() map[string][]*multipart.FileHeader

Files returns all file headers for a multipart form

func (*Request) FormValue

func (r *Request) FormValue(key string) string

FormValue returns a form value

func (*Request) FormValueDefault

func (r *Request) FormValueDefault(key, defaultValue string) string

FormValueDefault returns a form value or default

func (*Request) FormValues

func (r *Request) FormValues() url.Values

FormValues returns all form values

func (*Request) FullURL

func (r *Request) FullURL() string

FullURL returns the full URL of the request

func (*Request) GetAuth

func (r *Request) GetAuth() *Auth

GetAuth extracts and analyzes authentication information

func (*Request) HasAuth

func (r *Request) HasAuth() bool

HasAuth checks if the request has any authentication

func (*Request) HasHeader

func (r *Request) HasHeader(key string) bool

HasHeader checks if a header exists

func (*Request) HeaderValue

func (r *Request) HeaderValue(key string) string

HeaderValue returns a header value

func (*Request) HeaderValues

func (r *Request) HeaderValues(key string) []string

HeaderValues returns all header values for a key

func (*Request) IsAjax

func (r *Request) IsAjax() bool

IsAjax checks if the request is an AJAX request

func (*Request) IsAuthType

func (r *Request) IsAuthType(authType string) bool

IsAuthType checks if the request uses a specific auth type

func (*Request) IsSecure

func (r *Request) IsSecure() bool

IsSecure checks if the request is HTTPS

func (*Request) PostFormValue

func (r *Request) PostFormValue(key string) string

PostFormValue returns a POST form value (excluding query params)

func (*Request) PostFormValues

func (r *Request) PostFormValues() url.Values

PostFormValues returns all POST form values

func (*Request) QueryParam

func (r *Request) QueryParam(key string) string

QueryParam returns a query parameter value

func (*Request) QueryParamBool

func (r *Request) QueryParamBool(key string) (bool, error)

QueryParamBool returns a query parameter as boolean

func (*Request) QueryParamBoolDefault

func (r *Request) QueryParamBoolDefault(key string, defaultValue bool) bool

QueryParamBoolDefault returns a query parameter as boolean or default

func (*Request) QueryParamDefault

func (r *Request) QueryParamDefault(key, defaultValue string) string

QueryParamDefault returns a query parameter value or default

func (*Request) QueryParamInt

func (r *Request) QueryParamInt(key string) (int, error)

QueryParamInt returns a query parameter as integer

func (*Request) QueryParamIntDefault

func (r *Request) QueryParamIntDefault(key string, defaultValue int) int

QueryParamIntDefault returns a query parameter as integer or default

func (*Request) QueryParams

func (r *Request) QueryParams() url.Values

QueryParams returns all query parameters

func (*Request) Referer

func (r *Request) Referer() string

Referer returns the Referer header

func (*Request) Scheme

func (r *Request) Scheme() string

Scheme returns the request scheme (http or https)

func (*Request) SmartBind

func (r *Request) SmartBind(obj interface{}) error

SmartBind automatically detects content type and binds accordingly

func (*Request) UserAgent

func (r *Request) UserAgent() string

UserAgent returns the User-Agent header

type ValidationError

type ValidationError struct {
	Field   string      `json:"field"`
	Value   interface{} `json:"value"`
	Message string      `json:"message"`
	Tag     string      `json:"tag"`
}

ValidationError represents a validation error with field details

func (ValidationError) Error

func (v ValidationError) Error() string

Error implements the error interface

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors represents multiple validation errors

func (ValidationErrors) Error

func (ve ValidationErrors) Error() string

Error implements the error interface

func (ValidationErrors) HasErrors

func (ve ValidationErrors) HasErrors() bool

HasErrors returns true if there are validation errors

Jump to

Keyboard shortcuts

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