http

package
v0.0.0-...-d4b30f7 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2022 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

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

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 DynamicResponse

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

body isn't known until runtime, but we know the status and code and can put those in logData

func OkBytes

func OkBytes(body []byte) DynamicResponse

func Validation

func Validation(validator *validation.Result) DynamicResponse

func (DynamicResponse) EnhanceLog

func (r DynamicResponse) EnhanceLog(logger log.Logger) log.Logger

func (DynamicResponse) Write

func (r DynamicResponse) Write(conn *fasthttp.RequestCtx)

type Env

type Env interface {
	Release()
	RequestId() string
	Info(string) log.Logger
	Error(string) log.Logger
}

type ErrorIdResponse

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

func (ErrorIdResponse) EnhanceLog

func (r ErrorIdResponse) EnhanceLog(logger log.Logger) log.Logger

func (ErrorIdResponse) Write

func (r ErrorIdResponse) Write(conn *fasthttp.RequestCtx)

type Response

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

func Ok

func Ok(data any) Response

func SerializationError

func SerializationError() Response

func ServerError

func ServerError() 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) EnhanceLog

func (r StaticResponse) EnhanceLog(logger log.Logger) log.Logger

func (StaticResponse) Write

func (r StaticResponse) Write(conn *fasthttp.RequestCtx)

Jump to

Keyboard shortcuts

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