http

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 6 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ValidationLogData = log.NewField().
						Int("_code", utils.RES_VALIDATION).
						Int("status", 400).
						Finalize()

	OKLogData = log.NewField().
				Int("status", 200).
				Finalize()

	CreatedLogData = log.NewField().
					Int("status", 201).
					Finalize()
)
View Source
var (
	InvalidJSON = StaticError(400, utils.RES_INVALID_JSON_PAYLOAD, "invalid json payload")
)

Functions

func Handler

func Handler[T Env](routeName string, loadEnv func(ctx *fasthttp.RequestCtx) (T, Response, error), next func(ctx *fasthttp.RequestCtx, env T) (Response, error)) func(ctx *fasthttp.RequestCtx)

func NoEnvHandler

func NoEnvHandler(routeName string, next func(ctx *fasthttp.RequestCtx) (Response, error)) func(ctx *fasthttp.RequestCtx)

Types

type Env

type Env interface {
	Release()
	RequestId() string
	Request(string) log.Logger
	Error(string) log.Logger
	ServerError(err error, conn *fasthttp.RequestCtx) Response
}

type ErrorIdResponse

type ErrorIdResponse struct {
	Err     error
	ErrorId string
	Body    []byte
	LogData log.Field
}

func NewErrorIdResponse added in v0.0.7

func NewErrorIdResponse(err error, errorId string, body []byte, logData log.Field) ErrorIdResponse

func (ErrorIdResponse) Write

func (r ErrorIdResponse) Write(conn *fasthttp.RequestCtx, logger log.Logger) log.Logger

type JSONResponse added in v0.0.7

type JSONResponse struct {
	Body    []byte
	LogData log.Field
	Status  int
}

func (JSONResponse) Write added in v0.0.7

func (r JSONResponse) Write(conn *fasthttp.RequestCtx, logger log.Logger) log.Logger

type Response

type Response interface {
	// return logger for chaining
	Write(conn *fasthttp.RequestCtx, logger log.Logger) log.Logger
}

func Created added in v0.0.7

func Created(data any) Response

func NewJSONResponse added in v0.0.7

func NewJSONResponse(data any, status int, logData log.Field) Response

func OK added in v0.0.7

func OK(data any) Response

func OKBytes added in v0.0.7

func OKBytes(body []byte) Response

func SerializationError

func SerializationError(err error) Response

func ServerError

func ServerError(err error, fullError bool) Response

func Validation

func Validation(validator ValidationProvider) Response

type StaticResponse

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

We know the status/body/logData upfront (lets us optimize EnhanceLog)

func StaticError

func StaticError(status int, code int, error string) StaticResponse

func StaticNotFound

func StaticNotFound(code int) StaticResponse

func (StaticResponse) Write

func (r StaticResponse) Write(conn *fasthttp.RequestCtx, logger log.Logger) log.Logger

type ValidationProvider added in v0.0.6

type ValidationProvider interface {
	Errors() []any
}

Jump to

Keyboard shortcuts

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