http

package
v0.0.0-...-685c49b Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	API = map[string]*Route{}
)
View Source
var (
	SaiHttpServer = &HttpServer{}
)

Functions

func BadRequestError

func BadRequestError() *common.Error

func MethodNotAllowed

func MethodNotAllowed(ctx *fasthttp.RequestCtx)

func MethodNotAllowedError

func MethodNotAllowedError(method string) *common.Error

func NotFound

func NotFound(ctx *fasthttp.RequestCtx)

func NoteTime

func NoteTime(next http.Handler) http.Handler

func RegisterHandlers

func RegisterHandlers(router *fasthttprouter.Router)

func RouteNotFindError

func RouteNotFindError(path string) *common.Error

func SetErrorResponse

func SetErrorResponse(ctx *fasthttp.RequestCtx, err *common.Error)

func SetHttpServerInv

func SetHttpServerInv(httpServer HttpServer)

func SetResponse

func SetResponse(ctx *fasthttp.RequestCtx, resp []byte)

func SetResponseError

func SetResponseError(w *http.ResponseWriter, error2 *common.Error)

Types

type HttpRequest

type HttpRequest struct {
	Query           url.Values
	Body            map[string]interface{}
	Params          map[string]interface{}
	Route           *Route
	Session         *auth.Session
	Response        *Response
	ResponseChannel chan *Response
}

func CreateRequest

func CreateRequest() HttpRequest

func GetRequest

func GetRequest(req *http.Request, route *Route) (*HttpRequest, *common.Error)

func (*HttpRequest) GetParam

func (httpRequest *HttpRequest) GetParam(key string) (interface{}, bool)

func (*HttpRequest) ParseParams

func (httpRequest *HttpRequest) ParseParams()

type HttpServer

type HttpServer struct {
	Host string `json:"host"`
	Port int    `json:"port"`
}

func (*HttpServer) Address

func (httpServer *HttpServer) Address() string

func (*HttpServer) Start

func (httpServer *HttpServer) Start()

type Middleware

type Middleware func(handler fasthttp.RequestHandler) fasthttp.RequestHandler

type MiddlewareChain

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

func CreateMiddlewareChain

func CreateMiddlewareChain(middlewares ...Middleware) *MiddlewareChain

func (*MiddlewareChain) Append

func (c *MiddlewareChain) Append(middlewares ...Middleware) *MiddlewareChain

func (*MiddlewareChain) Extend

func (*MiddlewareChain) Then

type Response

type Response struct {
	Body  []byte
	Code  int
	Error *common.Error
}

func (*Response) SetBody

func (resp *Response) SetBody(body []byte)

func (*Response) SetBodyString

func (resp *Response) SetBodyString(body string)

func (*Response) SetError

func (resp *Response) SetError(err *common.Error)

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc func(r *Route)
	Handlerr    func(*HttpRequest)
	Handler     fasthttp.RequestHandler
	RouteGroup  *RouteGroup
	Permission  auth.Rights
	Validations []Validation
}

func (*Route) Handle

func (route *Route) Handle(request *HttpRequest)

func (*Route) Register

func (route *Route) Register()

func (*Route) String

func (r *Route) String() string

type RouteGroup

type RouteGroup struct {
	Chain *MiddlewareChain
}

type Validation

type Validation struct {
	Key      string
	Type     string
	Rules    []string
	Required bool
}

Jump to

Keyboard shortcuts

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