recovers

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

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

Go to latest
Published: Sep 8, 2022 License: MIT Imports: 4 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Recover

Build Status

Middleware by error recover

⚙ Installation

go get -u github.com/eininst/fiber-middleware-recover

⚡ Quickstart

package main

import (
    "errors"
    recovers "github.com/eininst/fiber-middleware-recover"
    "github.com/gofiber/fiber/v2"
)

func main() {
    app := fiber.New()
    app.Use(recovers.New())

    app.Get("/", func(ctx *fiber.Ctx) error {
        panic(errors.New("my is error"))
        return ctx.Next()
    })
    _ = app.Listen(":8080")
}

http response: 500 (Internal Server Error)

Stack info: 

[ERROR] [88182] 2022/09/08 14:45:31 panic: my is error
goroutine 20 [running]:
github.com/eininst/fiber-middleware-recover.stackTraceHandler({0x1028cf1e0?, 0x1400011b4b0}, 0x500)
        /Users/wangziqing/go/fiber-middleware-recover/recover.go:36 +0x4c
github.com/eininst/fiber-middleware-recover.New.func1.1()
        /Users/wangziqing/go/fiber-middleware-recover/recover.go:56 +0x50
panic({0x1028cf1e0, 0x1400011b4b0})
        /usr/local/go/src/runtime/panic.go:884 +0x204
main.main.func1(0x1028d34a0?)
        /Users/wangziqing/go/fiber-middleware-recover/examples/main.go:14 +0x54
github.com/gofiber/fiber/v2.(*App).next(0x14000154f00, 0x14000176840)
        /Users/wangziqing/go/pkg/mod/github.com/gofiber/fiber/v2@v2.37.1/router.go:132 +0x184
github.com/gofiber/fiber/v2.(*Ctx).Next(0x14000054b18?)
        /Users/wangziqing/go/pkg/mod/github.com/gofiber/fiber/v2@v2.37.1/ctx.go:892 +0x5c
github.com/eininst/fiber-middleware-recover.New.func1(0x1028d34a0?)
        /Users/wangziqing/go/fiber-middleware-recover/recover.go:65 +0x70

See examples

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	StackTraceBufLen: 1280,
	Handler: func(r interface{}) *fiber.Error {
		if v, ok := r.(error); ok {
			return fiber.NewError(fiber.StatusInternalServerError, v.Error())
		}

		return fiber.NewError(fiber.StatusInternalServerError)
	},
}

Functions

func New

func New(config ...Config) fiber.Handler

Types

type Config

type Config struct {
	StackTraceBufLen int
	Handler          ErrorHandler
}

type ErrorHandler

type ErrorHandler func(r interface{}) *fiber.Error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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