fasthttp

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: MIT Imports: 5 Imported by: 0

README

sentrusfasthttp

Example

import (
	"github.com/orandin/sentrus"
	sentrusfasthttp "github.com/orandin/sentrus/fasthttp"
)

// Set up Sentry here

// Add hook
logrus.AddHook(sentrus.NewHook(
    []logrus.Level{logrus.WarnLevel, logrus.ErrorLevel},
    sentrus.WithCustomCaptureLog(sentrusfasthttp.CaptureLog),
))

sentryHandler := sentryfasthttp.New(sentryfasthttp.Options{
    Repanic: true,
    WaitForDelivery: true,
})

enhanceSentryEvent := func (handler fasthttp.RequestHandler) fasthttp.RequestHandler {
	return func(ctx *fasthttp.RequestCtx) {
		if hub := sentry.GetHubFromContext(ctx); hub != nil {
			hub.Scope().SetTag("someRandomTag", "maybeYouNeedIt")
		}
		handler(ctx)
	}
}

defaultHandler := enhanceSentryEvent(func (ctx *fasthttp.RequestCtx) {
	logHandler := logrus.WithContext(ctx)
	logHandler.Warn("Ceci est un test")

	ctx.SetStatusCode(fasthttp.StatusOK)
})

fooHandler := enhanceSentryEvent(func (ctx *fasthttp.RequestCtx) {
	panic("y tho")
})

fastHTTPHandler := func (ctx *fasthttp.RequestCtx) {
	switch string(ctx.Path()) {
	case "/foo":
		fooHandler(ctx)
	default:
		defaultHandler(ctx)
	}
}

fmt.Println("Listening and serving HTTP on :3000")

if err := fasthttp.ListenAndServe(":3000", sentryHandler.Handle(fastHTTPHandler)); err != nil {
    panic(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureLog

func CaptureLog(entry *logrus.Entry, defaultHub *sentry.Hub, tags map[string]string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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