owlsome-official / zlogres

zlogres is a middleware for GoFiber that logging about api elapsed time since request to response.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

zlogres

made-with-Go Watsize-Library CodeQL

zlogres is a middleware for GoFiber that logging about api elapsed time since request to response.

Table of Contents

Installation

  go get -u github.com/owlsome-official/zlogres

Signatures

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

Examples

Import the middleware package that is part of the Fiber web framework

import (
  "github.com/gofiber/fiber/v2"
  "github.com/owlsome-official/zlogres"
)

After you initiate your Fiber app, you can use the following possibilities:

// Default
app.Use(zlogres.New())

// this middleware supported the `requestid` middleware
app.Use(requestid.New())
app.Use(zlogres.New())

// Or extend your config for customization
app.Use(requestid.New(requestid.Config{
  ContextKey: "transaction-id",
}))
app.Use(zlogres.New(zlogres.Config{
  RequestIDContextKey: "transaction-id",
}))

Config

// Config defines the config for middleware.
type Config struct {
  // Optional. Default: nil
  Next func(c *fiber.Ctx) bool

  // Optional. Default: "requestid"
  RequestIDContextKey string
}

Default Config

var ConfigDefault = Config{
  Next:                nil,
  RequestIDContextKey: "requestid",
}

Dependencies

Example Usage

Please go to example/main.go

Don't forget to run:

  go mod tidy

Note: Custom usage please focus on Custom section

About

zlogres is a middleware for GoFiber that logging about api elapsed time since request to response.


Languages

Language:Go 100.0%