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 ¶
- func BindAll(r *http.Request, params map[string]string, obj interface{}) error
- func BindForm(r *http.Request, obj interface{}) error
- func BindHeader(r *http.Request, obj interface{}) error
- func BindJSON(r *http.Request, obj interface{}) error
- func BindPath(params map[string]string, obj interface{}) error
- func BindQuery(r *http.Request, obj interface{}) error
- func BindXML(r *http.Request, obj interface{}) error
- func BindYAML(r *http.Request, obj interface{}) error
- func GetContentType(r *http.Request) string
- func IsForm(r *http.Request) bool
- func IsJSON(r *http.Request) bool
- func IsXML(r *http.Request) bool
- func IsYAML(r *http.Request) bool
- func SmartBind(r *http.Request, obj interface{}) error
- func Validate(obj interface{}) error
- type Auth
- type Request
- func (r *Request) Accept() string
- func (r *Request) AcceptEncoding() string
- func (r *Request) AcceptLanguage() string
- func (r *Request) AcceptsHTML() bool
- func (r *Request) AcceptsJSON() bool
- func (r *Request) AcceptsPlainText() bool
- func (r *Request) AcceptsXML() bool
- func (r *Request) AcceptsYAML() bool
- func (r *Request) AuthToken() string
- func (r *Request) AuthType() string
- func (r *Request) Authorization() string
- func (r *Request) BaseURL() string
- func (r *Request) BearerToken() string
- func (r *Request) Body() ([]byte, error)
- func (r *Request) ClientIP() string
- func (r *Request) ContentLength() int64
- func (r *Request) ContentType() string
- func (r *Request) Cookie(name string) (*http.Cookie, error)
- func (r *Request) CookieValue(name string) (string, error)
- func (r *Request) CookieValueDefault(name, defaultValue string) string
- func (r *Request) FileHeader(key string) (*multipart.FileHeader, error)
- func (r *Request) Files() map[string][]*multipart.FileHeader
- func (r *Request) FormValue(key string) string
- func (r *Request) FormValueDefault(key, defaultValue string) string
- func (r *Request) FormValues() url.Values
- func (r *Request) FullURL() string
- func (r *Request) GetAuth() *Auth
- func (r *Request) HasAuth() bool
- func (r *Request) HasHeader(key string) bool
- func (r *Request) HeaderValue(key string) string
- func (r *Request) HeaderValues(key string) []string
- func (r *Request) IsAjax() bool
- func (r *Request) IsAuthType(authType string) bool
- func (r *Request) IsSecure() bool
- func (r *Request) PostFormValue(key string) string
- func (r *Request) PostFormValues() url.Values
- func (r *Request) QueryParam(key string) string
- func (r *Request) QueryParamBool(key string) (bool, error)
- func (r *Request) QueryParamBoolDefault(key string, defaultValue bool) bool
- func (r *Request) QueryParamDefault(key, defaultValue string) string
- func (r *Request) QueryParamInt(key string) (int, error)
- func (r *Request) QueryParamIntDefault(key string, defaultValue int) int
- func (r *Request) QueryParams() url.Values
- func (r *Request) Referer() string
- func (r *Request) Scheme() string
- func (r *Request) SmartBind(obj interface{}) error
- func (r *Request) UserAgent() string
- type ValidationError
- type ValidationErrors
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindHeader ¶
BindHeader binds HTTP headers to a struct
func GetContentType ¶
GetContentType returns the content type of the request
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 ¶
Request wraps http.Request with additional functionality
func (*Request) AcceptEncoding ¶
AcceptEncoding returns the Accept-Encoding header
func (*Request) AcceptLanguage ¶
AcceptLanguage returns the Accept-Language header
func (*Request) AcceptsHTML ¶
AcceptsHTML checks if the client accepts HTML responses
func (*Request) AcceptsJSON ¶
AcceptsJSON checks if the client accepts JSON responses
func (*Request) AcceptsPlainText ¶
AcceptsPlainText checks if the client accepts plain text responses
func (*Request) AcceptsXML ¶
AcceptsXML checks if the client accepts XML responses
func (*Request) AcceptsYAML ¶
AcceptsYAML checks if the client accepts YAML responses
func (*Request) Authorization ¶
Authorization returns the Authorization header
func (*Request) BearerToken ¶
BearerToken extracts Bearer token from Authorization header
func (*Request) ContentLength ¶
ContentLength returns the content length
func (*Request) ContentType ¶
ContentType returns the content type
func (*Request) CookieValue ¶
CookieValue returns a cookie value as string
func (*Request) CookieValueDefault ¶
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) FormValueDefault ¶
FormValueDefault returns a form value or default
func (*Request) FormValues ¶
FormValues returns all form values
func (*Request) HeaderValue ¶
HeaderValue returns a header value
func (*Request) HeaderValues ¶
HeaderValues returns all header values for a key
func (*Request) IsAuthType ¶
IsAuthType checks if the request uses a specific auth type
func (*Request) PostFormValue ¶
PostFormValue returns a POST form value (excluding query params)
func (*Request) PostFormValues ¶
PostFormValues returns all POST form values
func (*Request) QueryParam ¶
QueryParam returns a query parameter value
func (*Request) QueryParamBool ¶
QueryParamBool returns a query parameter as boolean
func (*Request) QueryParamBoolDefault ¶
QueryParamBoolDefault returns a query parameter as boolean or default
func (*Request) QueryParamDefault ¶
QueryParamDefault returns a query parameter value or default
func (*Request) QueryParamInt ¶
QueryParamInt returns a query parameter as integer
func (*Request) QueryParamIntDefault ¶
QueryParamIntDefault returns a query parameter as integer or default
func (*Request) QueryParams ¶
QueryParams returns all query parameters
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