rest

package
v0.0.0-...-9d6c436 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: Apache-2.0 Imports: 7 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 {
	Lifecycle *Lifecycle
	*fasthttp.RequestCtx
}

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) 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

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 Key

type Key string
const (
	AuthUserKey Key = "CURRENT_USER"
)

type Lifecycle

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

func NewLifecycle

func NewLifecycle(ctx context.Context) *Lifecycle

func (*Lifecycle) Destroy

func (l *Lifecycle) Destroy() int

func (*Lifecycle) Listen

func (l *Lifecycle) Listen(ctx context.Context) <-chan *lifecycleEvent

Listen: listen for lifecycle events

func (*Lifecycle) Write

func (l *Lifecycle) Write(event LifecyclePhase, d LifecycleEventData)

Write: send a lifecycle event

type LifecycleEventData

type LifecycleEventData interface{}

type LifecyclePhase

type LifecyclePhase int
const (
	LifecyclePhaseStarted LifecyclePhase = 1 + iota
	LifecyclePhaseWriteHeader
	LifecyclePhaseWriteBody
	LifecyclePhaseSetStatus
	LifecyclePhaseCompleted
)

type Map

type Map map[string]interface{}

type Middleware

type Middleware = func(ctx *Ctx) APIError

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