Home / File/ config.go — fiber Source File

config.go — fiber Source File

Architecture documentation for config.go, a go file in the fiber codebase. 1 imports, 0 dependents.

File go FiberCore Adapters 1 imports 2 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  296adaee_e5a5_098b_f97d_0b73acf76af5["config.go"]
  91e028e2_bdf9_8fcd_cf03_c8d86daaec3f["fs"]
  296adaee_e5a5_098b_f97d_0b73acf76af5 --> 91e028e2_bdf9_8fcd_cf03_c8d86daaec3f
  style 296adaee_e5a5_098b_f97d_0b73acf76af5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

package static

import (
	"io/fs"
	"time"

	"github.com/gofiber/fiber/v3"
)

// Config defines the config for middleware.
type Config struct {
	// FS is the file system to serve the static files from.
	// You can use interfaces compatible with fs.FS like embed.FS, os.DirFS etc.
	//
	// Optional. Default: nil
	FS fs.FS

	// Next defines a function to skip this middleware when returned true.
	//
	// Optional. Default: nil
	Next func(c fiber.Ctx) bool

	// ModifyResponse defines a function that allows you to alter the response.
	//
	// Optional. Default: nil
	ModifyResponse fiber.Handler

	// NotFoundHandler defines a function to handle when the path is not found.
	//
	// Optional. Default: nil
	NotFoundHandler fiber.Handler

	// The names of the index files for serving a directory.
	//
	// Optional. Default: []string{"index.html"}.
	IndexNames []string `json:"index"`

	// Expiration duration for inactive file handlers.
	// Use a negative time.Duration to disable it.
	//
	// Optional. Default: 10 * time.Second.
	CacheDuration time.Duration `json:"cache_duration"`

	// The value for the Cache-Control HTTP-header
	// that is set on the file response. MaxAge is defined in seconds.
	//
	// Optional. Default: 0.
	MaxAge int `json:"max_age"`

	// When set to true, the server tries minimizing CPU usage by caching compressed files.
	// This works differently than the github.com/gofiber/compression middleware.
	//
	// Optional. Default: false
	Compress bool `json:"compress"`

	// When set to true, enables byte range requests.
	//
	// Optional. Default: false
	ByteRange bool `json:"byte_range"`

	// When set to true, enables directory browsing.
	//
	// Optional. Default: false.
	Browse bool `json:"browse"`

	// When set to true, enables direct download.
	//
	// Optional. Default: false.
	Download bool `json:"download"`
}

// ConfigDefault is the default config
var ConfigDefault = Config{
	IndexNames:    []string{"index.html"},
	CacheDuration: 10 * time.Second,
}

// Helper function to set default values
func configDefault(config ...Config) Config {
	// Return default config if nothing provided
	if len(config) < 1 {
		return ConfigDefault
	}

	// Override default config
	cfg := config[0]

	// Set default values
	if len(cfg.IndexNames) == 0 {
		cfg.IndexNames = ConfigDefault.IndexNames
	}

	if cfg.CacheDuration == 0 {
		cfg.CacheDuration = ConfigDefault.CacheDuration
	}

	return cfg
}

Domain

Subdomains

Classes

Types

Dependencies

  • fs

Frequently Asked Questions

What does config.go do?
config.go is a source file in the fiber codebase, written in go. It belongs to the FiberCore domain, Adapters subdomain.
What functions are defined in config.go?
config.go defines 2 function(s): bool, configDefault.
What does config.go depend on?
config.go imports 1 module(s): fs.
Where is config.go in the architecture?
config.go is located at middleware/static/config.go (domain: FiberCore, subdomain: Adapters, directory: middleware/static).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free