httputils

package
v0.8.11 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	AllowOriginHeader  = "Access-Control-Allow-Origin"
	AllowHeadersHeader = "Access-Control-Allow-Headers"
	AllowMethodsHeader = "Access-Control-Allow-Methods"

	AllControlRequestHeader = "Access-Control-Request-Method"

	AllowCredentialsHeader = "Access-Control-Allow-Credentials"
	ExposeHeadersHeader    = "Access-Control-Expose-Headers"
	MaxAgeHeader           = "Access-Control-Max-Age"

	DatlyRequestMetricsHeader      = "Datly-Show-Metrics"
	DatlyInfoHeaderValue           = "info"
	DatlyDebugHeaderValue          = "debug"
	DatlyRequestDisableCacheHeader = "Datly-Disable-Cache"
	DatlyResponseHeaderMetrics     = "Datly-Metrics"

	DatlyServiceTimeHeader = "Datly-Service-Time"
	DatlyServiceInitHeader = "Datly-Service-init"

	//ContentTypeJSON json content type
	ContentTypeJSON = "application/json"

	CharsetUTF8 = "charset=utf-8"
	//EncodingGzip encoding gzip
	EncodingGzip = "gzip"

	ContentLength = "Content-Length"
)

Variables

This section is empty.

Functions

func BuildErrorResponse

func BuildErrorResponse(err error) (statusCode int, errorMessage string)

func Compress

func Compress(reader io.Reader) (*bytes.Buffer, error)

Compress compresses input using gzip

func WriteError

func WriteError(writer http.ResponseWriter, err error)

Types

type ClosableResponse

type ClosableResponse struct {
	http.ResponseWriter
	Closed bool
}

func NewClosableResponse

func NewClosableResponse(response http.ResponseWriter) *ClosableResponse

func (*ClosableResponse) WriteHeader

func (c *ClosableResponse) WriteHeader(statusCode int)

type Error

type Error struct {
	View       string      `json:",omitempty" default:"nullable=true,required=false,allowEmpty=true"`
	Parameter  string      `json:",omitempty" default:"nullable=true,required=false,allowEmpty=true"`
	StatusCode int         `json:",omitempty" default:"nullable=true,required=false,allowEmpty=true"`
	Err        error       `json:"-"`
	Message    string      `json:",omitempty" default:"nullable=true,required=false,allowEmpty=true"`
	Object     interface{} `json:",omitempty" default:"nullable=true,required=false,allowEmpty=true"`
}

func NewParamError

func NewParamError(view string, param string, err error, opts ...Option) *Error

func (*Error) Error

func (e *Error) Error() string

type Errors

type Errors struct {
	Message string `json:",omitempty" default:"nullable=true,required=false,allowEmpty=true"`
	Errors  []*Error
	// contains filtered or unexported fields
}

func NewErrors

func NewErrors() *Errors

func (*Errors) AddError

func (e *Errors) AddError(view, param string, err error, opts ...Option)

func (*Errors) Append

func (e *Errors) Append(err error)

func (*Errors) Error

func (e *Errors) Error() string

func (*Errors) ErrorStatusCode

func (e *Errors) ErrorStatusCode() int

func (*Errors) HasError

func (e *Errors) HasError() bool

func (*Errors) SetStatus

func (e *Errors) SetStatus(code int)

type HttpMessageError

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

func ErrorOf

func ErrorOf(defaultStatusCode int, err error) *HttpMessageError

func NewHttpMessageError

func NewHttpMessageError(statusCode int, err error) *HttpMessageError

func NewHttpStatusError

func NewHttpStatusError(statusCode int) *HttpMessageError

func (*HttpMessageError) Err

func (h *HttpMessageError) Err() error

func (*HttpMessageError) Error

func (h *HttpMessageError) Error() string

func (*HttpMessageError) ErrorMessage

func (h *HttpMessageError) ErrorMessage() string

func (*HttpMessageError) ErrorStatusCode

func (h *HttpMessageError) ErrorStatusCode() int

type Option

type Option func(e *Error)

func WithMessage

func WithMessage(msg string) Option

func WithObject

func WithObject(object interface{}) Option

func WithStatusCode

func WithStatusCode(code int) Option

type Request

type Request struct {
	Url           string            `velty:"-"`
	QueryParams   url.Values        `velty:"-"`
	PathVariables map[string]string `velty:"-"`
	Headers       http.Header       `velty:"-"`
	// contains filtered or unexported fields
}

func NewRequest

func NewRequest(cookies map[string]*http.Cookie, pathVariables map[string]string, queryParams url.Values, headers http.Header) *Request

func RequestOf

func RequestOf(r *http.Request, templateURI string) (*Request, error)

func (*Request) Cookie

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

func (*Request) HasCookie

func (r *Request) HasCookie(name string) bool

func (*Request) HasPathVariable

func (r *Request) HasPathVariable(name string) bool

func (*Request) HasQuery

func (r *Request) HasQuery(name string) bool

func (*Request) Path

func (r *Request) Path() string

func (*Request) PathVariable

func (r *Request) PathVariable(name string) string

func (*Request) QueryParam

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

func (*Request) RelativePath

func (r *Request) RelativePath() string

type Violations

type Violations []*validator.Violation

func (Violations) MergeCustom

func (v Violations) MergeCustom(custom map[string]interface{}) []*validator.Violation

func (Violations) MergeErrors

func (v Violations) MergeErrors(errors []*Error) []*validator.Violation

func (Violations) MergeGoViolation

func (v Violations) MergeGoViolation(violations []*govalidator.Violation) Violations

func (Violations) MergeSqlViolation

func (v Violations) MergeSqlViolation(violations []*sqlxvalidator.Violation) []*validator.Violation

Jump to

Keyboard shortcuts

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