http

package
v1.0.0-...-a0f063d Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	context.Context
	Context() context.Context
	WithValue(key string, value any)
	Request() Request
	Response() Response
}

type FormRequest

type FormRequest interface {
	Authorize(ctx Context) error
	Rules() map[string]string
	Messages() map[string]string
	Attributes() map[string]string
	PrepareForValidation(data validation.Data) error
}

type HandlerFunc

type HandlerFunc func(Context)

type ILimit

type ILimit interface {
	By(key string) ILimit
	Response(func(ctx Context)) ILimit
}

type IRateLimiter

type IRateLimiter interface {
	For(name string, callback func(ctx Context) ILimit)
	ForWithLimits(name string, callback func(ctx Context) []ILimit)
	Limiter(name string) func(ctx Context) []ILimit
}

type Json

type Json map[string]any

type Middleware

type Middleware func(Context)

type Request

type Request interface {
	Header(key, defaultValue string) string
	Headers() http.Header
	Method() string
	Path() string
	Url() string
	FullUrl() string
	Ip() string

	// Route Retrieve  an input item from the request: /users/{id}
	Route(key string) string
	RouteInt(key string) int
	RouteInt64(key string) int64
	// Query Retrieve a query string item form the request: /users?id=1
	Query(key string, defaultValue ...string) string
	QueryInt(key string, defaultValue ...int) int
	QueryInt64(key string, defaultValue ...int64) int64
	QueryBool(key string, defaultValue ...bool) bool
	QueryArray(key string) []string
	QueryMap(key string) map[string]string
	// Form Retrieve a form string item from the post: /users POST:id=1
	Form(key string, defaultValue ...string) string
	// Json Retrieve data from the post: /users JSON:{"id": 1}
	Json(key string, defaultValue ...string) string
	// Bind Retrieve JSON and bind to obj
	Bind(obj any) error
	ShouldBind(obj any) error
	ShouldBindQuery(obj any) error
	ShouldBindJSON(obj any) error
	ShouldBindUri(obj any) error
	// Input Retrieve data by order: json, form, query, route
	Input(key string, defaultValue ...string) string
	InputInt(key string, defaultValue ...int) int
	InputInt64(key string, defaultValue ...int64) int64
	InputBool(key string, defaultValue ...bool) bool

	File(name string) (filesystem.File, error)

	AbortWithStatus(code int)
	AbortWithStatusJson(code int, jsonObj any)

	Next()
	Origin() *http.Request

	Validate(rules map[string]string, options ...validation.Option) (validation.Validator, error)
	ValidateRequest(request FormRequest) (validation.Errors, error)

	Cookie(name string) (string, error)
}

type Response

type Response interface {
	Data(code int, contentType string, data []byte)
	Download(filepath, filename string)
	File(filepath string)
	Header(key, value string) Response
	SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool) Response
	Json(code int, obj any)
	Origin() ResponseOrigin
	Redirect(code int, location string)
	String(code int, format string, values ...any)
	Success() ResponseSuccess
	Error() ResponseError
	Writer() http.ResponseWriter
}

type ResponseError

type ResponseError interface {
	Data(contentType string, data []byte)
	Json(code int, msg string, err error)
	String(format string, values ...any)
}

type ResponseOrigin

type ResponseOrigin interface {
	Body() *bytes.Buffer
	Header() http.Header
	Size() int
	Status() int
}

type ResponseSuccess

type ResponseSuccess interface {
	Data(contentType string, data []byte)
	Json(code int, msg string, data any)
	String(format string, values ...any)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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