fiberx

package
Version: v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHandler = func(c *fiber.Ctx, err error) error {
	code := fiber.StatusInternalServerError
	res := Response{
		Code:    code,
		Message: utils.StatusMessage(code),
	}

	if errs, ok := err.(validator.ValidationErrors); ok {
		res.Code = fiber.StatusUnprocessableEntity
		res.Message = ""
		res.Data = removeTopStruct(errs.Translate(trans))
	} else if e, ok := err.(*fiber.Error); ok {
		res.Code = e.Code
		res.Message = e.Message
	}

	return Resp(c, res.Code, res)
}

ErrHandler is Dawn's error handler

V is an instance of *validator.Validate used for custom registrations.

Functions

func Data

func Data(c *fiber.Ctx, data interface{}) error

Data returns data with status code OK by default

func Logger

func Logger() fiber.Handler

Logger logs request and response info to os.Stdout or os.Stderr. The format is: time #pid[-request-id]: latency status clientIP method protocol://host_path[ error]

func Message

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

Message wraps for RespOK with required message

func MobileRule

func MobileRule(fl validator.FieldLevel) bool

MobileRule validates mobile phone number

func Resp

func Resp(c *fiber.Ctx, statusCode int, res Response) error

Resp returns the custom response

func RespAccepted

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

RespAccepted responses with status code 202 RFC 7231, 6.3.3

func RespAlreadyReported

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

RespAlreadyReported responses with status code 208 RFC 5842, 7.1

func RespCreated

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

RespCreated responses with status code 201 RFC 7231, 6.3.2

func RespMultiStatus

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

RespMultiStatus responses with status code 207 RFC 4918, 11.1

func RespNoContent

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

RespNoContent responses with status code 204 RFC 7231, 6.3.5

func RespNonAuthoritativeInformation

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

RespNonAuthoritativeInformation responses with status code 203 RFC 7231, 6.3.4

func RespOK

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

RespOK responses with status code 200 RFC 7231, 6.3.1

func RespPartialContent

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

RespPartialContent responses with status code 206 RFC 7233, 4.1

func RespResetContent

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

RespResetContent responses with status code 205 RFC 7231, 6.3.6

func ValidateBody

func ValidateBody(c *fiber.Ctx, obj interface{}) (err error)

ValidateBody accepts a obj holds results from BodyParser and then do the validation by a validator

func ValidateQuery

func ValidateQuery(c *fiber.Ctx, obj interface{}) (err error)

ValidateQuery accepts a obj holds results from QueryParser and then do the validation by a validator

Types

type Response

type Response struct {
	// Code is the status code by default, but also can be
	// a custom code
	Code int `json:"code,omitempty"`
	// Message shows detail thing back to caller
	Message string `json:"message,omitempty"`
	// RequestID needs to be used with middleware
	RequestID string `json:"request_id,omitempty"`
	// Data accepts any thing as the response data
	Data interface{} `json:"data,omitempty"`
}

Response is a unified format for api results

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL