README

Favicon

Favicon middleware ignores favicon requests or caches a provided icon in memory to improve performance by skipping disk access. User agents request /favicon.ico frequently and indiscriminately, so you may wish to exclude these requests from your logs by using this middleware before your logger middleware.

Note: This middleware is exclusively for serving the default, implicit favicon, which is GET /favicon.ico.

Signatures
func New(config ...Config) fiber.Handler
Config
// Config defines the config for middleware.
type Config struct {
	// Next defines a function to skip this middleware when returned true.
	//
	// Optional. Default: nil
	Next func(c *fiber.Ctx) bool

	// File holds the path to an actual favicon that will be cached
	//
	// Optional. Default: ""
	File string
}
Example

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

import (
  "github.com/gofiber/fiber"
  "github.com/gofiber/fiber/middleware/favicon"
)

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

// Default favicon config
app.Use(favicon.New())

// Provide a custom favicon to load into memory
app.Use(favicon.New(favicon.Config{
    File: "./favicon.ico",
}))

// Skip middleware for specific routes
app.Use(compress.New(compress.Config{
  Next:  func(c *fiber.Ctx) bool {
    return c.Path() == "/admin"
  },
  File: "./favicon.ico",
}))
Expand ▾ Collapse ▴

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Next: nil,
	File: "",
}

    ConfigDefault is the default config

    Functions

    func New

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

      New creates a new middleware handler

      Types

      type Config

      type Config struct {
      	// Next defines a function to skip this middleware when returned true.
      	//
      	// Optional. Default: nil
      	Next func(c *fiber.Ctx) bool
      
      	// File holds the path to an actual favicon that will be cached
      	//
      	// Optional. Default: ""
      	File string
      }

        Config defines the config for middleware.

        Source Files