access

package
Version: v3.0.0-...-e1df10c Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package access provides an access logging handler for the ozzo routing package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CustomLogger

func CustomLogger(loggerFunc LogWriterFunc) routing.Handler

CustomLogger returns a handler that calls the LogWriterFunc passed to it for every request. The LogWriterFunc is provided with the http.Request and LogResponseWriter objects for the request, as well as the elapsed time since the request first came through the middleware. LogWriterFunc can then do whatever logging it needs to do.

import (
    "log"
    "net/http"

    "github.com/rmnoff/fasthttp-routing/v3"
    "github.com/rmnoff/fasthttp-routing/v3/access"
)

func myCustomLogger(req http.Context, res access.LogResponseWriter, elapsed int64) {
    // Do something with the request, response, and elapsed time data here
}
r := routing.New()
r.Use(access.CustomLogger(myCustomLogger))

func GetClientIP

func GetClientIP(ctx *fasthttp.RequestCtx) string

GetClientIP returns the originating IP for a request.

func Logger

func Logger(logf LogFunc) routing.Handler

Logger returns a handler that logs a message for every request. The access log messages contain information including client IPs, time used to serve each request, request line, response status and size.

import (
    "log"
    "github.com/rmnoff/fasthttp-routing/v3"
    "github.com/rmnoff/fasthttp-routing/v3/access"
)

r := routing.New()
r.Use(access.Logger(log.Printf))

Types

type LogFunc

type LogFunc func(format string, a ...interface{})

LogFunc logs a message using the given format and optional arguments. The usage of format and arguments is similar to that for fmt.Printf(). LogFunc should be thread safe.

type LogWriterFunc

type LogWriterFunc func(ctx *fasthttp.RequestCtx, elapsed float64)

LogWriterFunc takes in the request and responseWriter objects as well as a float64 containing the elapsed time since the request first passed through this middleware and does whatever log writing it wants with that information. LogWriterFunc should be thread safe.

Source Files

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