rest

package
v0.0.0-...-6d36bb5 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError = errors.APIError

type APIErrorResponse

type APIErrorResponse struct {
	StatusCode HttpStatusCode         `json:"status_code"`
	Status     string                 `json:"status"`
	Error      string                 `json:"error"`
	ErrorCode  int                    `json:"error_code"`
	Details    map[string]interface{} `json:"details,omitempty"`
}

type Ctx

type Ctx struct {
	*fasthttp.RequestCtx
}

func (*Ctx) ClientIP

func (c *Ctx) ClientIP() string

func (*Ctx) GetActor

func (c *Ctx) GetActor() (structures.User, bool)

Get the current authenticated user

func (*Ctx) JSON

func (c *Ctx) JSON(status HttpStatusCode, v interface{}) APIError

func (*Ctx) Log

func (c *Ctx) Log() *zap.SugaredLogger

func (*Ctx) SetActor

func (c *Ctx) SetActor(u structures.User)

Set the current authenticated user

func (*Ctx) SetStatusCode

func (c *Ctx) SetStatusCode(code HttpStatusCode)

func (*Ctx) StatusCode

func (c *Ctx) StatusCode() HttpStatusCode

func (*Ctx) UserValue

func (c *Ctx) UserValue(key constant.Key) *Param

type HttpStatusCode

type HttpStatusCode int
const (
	// 1xx Informational
	Continue          HttpStatusCode = 100
	SwitchingProtocol HttpStatusCode = 101
	Processing        HttpStatusCode = 102
	EarlyHints        HttpStatusCode = 103

	// 2xx Successful
	OK                          HttpStatusCode = 200
	Created                     HttpStatusCode = 201
	Accepted                    HttpStatusCode = 202
	NonAuthoritativeInformation HttpStatusCode = 203
	NoContent                   HttpStatusCode = 204
	ResetContent                HttpStatusCode = 205
	PartialContent              HttpStatusCode = 206
	MultiStatus                 HttpStatusCode = 207
	AlreadyReported             HttpStatusCode = 208
	IMUsed                      HttpStatusCode = 226

	// 3xx Redirections
	MultipleChoice    HttpStatusCode = 300
	MovedPermanently  HttpStatusCode = 301
	Found             HttpStatusCode = 302
	SeeOther          HttpStatusCode = 303
	NotModified       HttpStatusCode = 304
	TemporaryRedirect HttpStatusCode = 307
	PermanentRedirect HttpStatusCode = 308

	// 4xx Client Errors
	BadRequest                  HttpStatusCode = 400
	Unauthorized                HttpStatusCode = 401
	PaymentRequired             HttpStatusCode = 402
	Forbidden                   HttpStatusCode = 403
	NotFound                    HttpStatusCode = 404
	MethodNotAllowed            HttpStatusCode = 405
	NotAcceptable               HttpStatusCode = 406
	ProxyAuthenticationRequired HttpStatusCode = 407
	RequestTimeout              HttpStatusCode = 408
	Conflict                    HttpStatusCode = 409
	Gone                        HttpStatusCode = 410
	LengthRequired              HttpStatusCode = 411
	PreconditionFailed          HttpStatusCode = 412
	PayloadTooLarge             HttpStatusCode = 413
	URITooLong                  HttpStatusCode = 414
	UnsupportedMediaType        HttpStatusCode = 415
	RangeNotSatisfiable         HttpStatusCode = 416
	ExpectationFailed           HttpStatusCode = 417
	ImATeapot                   HttpStatusCode = 418
	MisdirectedRequest          HttpStatusCode = 421
	UnprocessableEntity         HttpStatusCode = 422
	Locked                      HttpStatusCode = 423
	FailedDependency            HttpStatusCode = 424
	TooEarly                    HttpStatusCode = 425
	UpgradeRequired             HttpStatusCode = 426
	PreconditionRequired        HttpStatusCode = 428
	TooManyRequests             HttpStatusCode = 429
	RequestHeaderFieldsTooLarge HttpStatusCode = 431
	UnavailableForLegalReasons  HttpStatusCode = 451

	// 5xx Server Errors
	InternalServerError           HttpStatusCode = 500
	NotImplemented                HttpStatusCode = 501
	BadGateway                    HttpStatusCode = 502
	ServiceUnavailable            HttpStatusCode = 503
	GatewayTimeout                HttpStatusCode = 504
	HttpVersionNotSupported       HttpStatusCode = 505
	VariantAlsoNegotiates         HttpStatusCode = 506
	InsufficientStorage           HttpStatusCode = 507
	LoopDetected                  HttpStatusCode = 508
	NotExtended                   HttpStatusCode = 510
	NetworkAuthenticationRequired HttpStatusCode = 511
)

func (HttpStatusCode) String

func (c HttpStatusCode) String() string

String: return the http status code in text form

type Map

type Map map[string]interface{}

type Middleware

type Middleware = func(ctx *Ctx) APIError

type Param

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

func (*Param) Int32

func (p *Param) Int32() (int32, error)

Int32 parses the param into an int32

func (*Param) Int64

func (p *Param) Int64() (int64, error)

Int64 parses the param into an int64

func (*Param) ObjectID

func (p *Param) ObjectID() (primitive.ObjectID, error)

ObjectID parses the param into an Object ID

func (*Param) String

func (p *Param) String() (string, bool)

String returns a string value of the param

func (*Param) User

func (p *Param) User() structures.User

type Route

type Route interface {
	Config() RouteConfig
	Handler(ctx *Ctx) APIError
}

type RouteConfig

type RouteConfig struct {
	URI        string
	Method     RouteMethod
	Children   []Route
	Middleware []Middleware
}

type RouteMethod

type RouteMethod string
const (
	GET     RouteMethod = "GET"
	POST    RouteMethod = "POST"
	PUT     RouteMethod = "PUT"
	PATCH   RouteMethod = "PATCH"
	DELETE  RouteMethod = "DELETE"
	OPTIONS RouteMethod = "OPTIONS"
)

type Router

type Router = router.Router

Jump to

Keyboard shortcuts

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