www

package module
v0.0.0-...-7d4cc9f Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: BSD-3-Clause Imports: 19 Imported by: 0

README

www

Some helpers around go fiber

Documentation

Index

Constants

View Source
const ContentType = "application/json; charset=utf-8"
View Source
const DefaultMaxOffset = int64(math.MaxInt16)
View Source
const DefaultMaxSize = int64(100)

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(c *fiber.Ctx, body interface{}) error

returns a 400 BadRequest response with the given body

func Conflict

func Conflict(c *fiber.Ctx, body interface{}) error

func Created

func Created(c *fiber.Ctx, body interface{}) error

returns a 201 Created response with the given body

func ErrConflict

func ErrConflict(c *fiber.Ctx, msg ...string) error

func ErrForbidden

func ErrForbidden(c *fiber.Ctx) error

func ErrGone

func ErrGone(c *fiber.Ctx) error

func ErrInternal

func ErrInternal(c *fiber.Ctx, err error) error

func ErrMethodNotAllowed

func ErrMethodNotAllowed(c *fiber.Ctx) error

func ErrNotFound

func ErrNotFound(c *fiber.Ctx) error

func ErrToManyRequests

func ErrToManyRequests(c *fiber.Ctx) error

func ErrUnauthorized

func ErrUnauthorized(c *fiber.Ctx) error

func Int64

func Int64(c *fiber.Ctx, key string) (int64, error)

func Json

func Json(errNotFound error) fiber.Handler

func Ok

func Ok(c *fiber.Ctx, body interface{}) error

returns a 200 OK response with the given body

func OkErr

func OkErr(c *fiber.Ctx, err error) error

returns a 200 OK response with an empty body or the given error if the error is not nil

func Paginated

func Paginated(next func(*fiber.Ctx, Pagination) error, params ...int64) fiber.Handler

Paginated is a middleware that parses the limit and offset parameters from the query string. takes two optional parameters: the maximum limit and the maximum offset.

Only GET requests are allowed to use this middleware

func ParseData

func ParseData[T any](r io.Reader) (*T, error)

func Parser

func Parser[T any](next func(*fiber.Ctx, *T) error) fiber.Handler

Parser is a middleware that parse the body of the request and validates it. An invalid validation returns a 400 Bad Request with a JSON body containing the validation errors. Here is an example response: {"status":"fail","data":{"validation":{"name":"name is a required field"}}}

func Raw

func Raw(c *fiber.Ctx, status int, body interface{}) error

func Serve

func Serve(route Route, config ServerConfig) error

Serve starts an instance of the http server.

func Start

func Start()

func Translator

func Translator() ut.Translator

func Validator

func Validator() *validator.Validate

Types

type Body

type Body map[string]interface{}

type Entries

type Entries struct {
	Name string
	Data interface{}
}

func Obj

func Obj(key string, data interface{}) Entries

type Option

type Option func(*ServerConfig)

type Pagination

type Pagination struct {
	Limit  int64 `json:"limit"`
	Offset int64 `json:"offset"`
}

type Response

type Response struct {
	Status  Status      `json:"status"`
	Data    interface{} `json:"data,omitempty"`
	Message string      `json:"message,omitempty"`
}

type Route

type Route func(r fiber.Router)

type ServerConfig

type ServerConfig struct {
	Port      int
	Timeout   time.Duration
	BodyLimit int
	Logs      bool
	Origins   []string
}

type Status

type Status string
const (
	Success Status = "success"
	Fail    Status = "fail"
	Error   Status = "error"
)

Jump to

Keyboard shortcuts

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