Home / File/ limiter.go — fiber Source File

limiter.go — fiber Source File

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

File go FiberMiddleware Caching 1 imports 2 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  c6253bbf_a478_e481_4b02_a86f58ccf743["limiter.go"]
  fcef1725_af89_d6cd_36cd_b228cdcc5acd["errors"]
  c6253bbf_a478_e481_4b02_a86f58ccf743 --> fcef1725_af89_d6cd_36cd_b228cdcc5acd
  style c6253bbf_a478_e481_4b02_a86f58ccf743 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

package limiter

import (
	"errors"

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

const (
	// X-RateLimit-* headers
	xRateLimitLimit     = "X-RateLimit-Limit"
	xRateLimitRemaining = "X-RateLimit-Remaining"
	xRateLimitReset     = "X-RateLimit-Reset"
)

// Handler defines a rate-limiting strategy that can produce a middleware
// handler using the provided configuration.
type Handler interface {
	New(config *Config) fiber.Handler
}

// New creates a new middleware handler
func New(config ...Config) fiber.Handler {
	// Set default config
	cfg := configDefault(config...)

	// Return the specified middleware handler.
	return cfg.LimiterMiddleware.New(&cfg)
}

// getEffectiveStatusCode returns the actual status code, considering both the error and response status
func getEffectiveStatusCode(c fiber.Ctx, err error) int {
	// If there's an error and it's a *fiber.Error, use its status code
	if err != nil {
		var fiberErr *fiber.Error
		if errors.As(err, &fiberErr) {
			return fiberErr.Code
		}
	}

	// Otherwise, use the response status code
	return c.Response().StatusCode()
}

Subdomains

Classes

Dependencies

  • errors

Frequently Asked Questions

What does limiter.go do?
limiter.go is a source file in the fiber codebase, written in go. It belongs to the FiberMiddleware domain, Caching subdomain.
What functions are defined in limiter.go?
limiter.go defines 2 function(s): New, getEffectiveStatusCode.
What does limiter.go depend on?
limiter.go imports 1 module(s): errors.
Where is limiter.go in the architecture?
limiter.go is located at middleware/limiter/limiter.go (domain: FiberMiddleware, subdomain: Caching, directory: middleware/limiter).

Analyze Your Own Codebase

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

Try Supermodel Free