Home / Function/ rotateWindow() — fiber Function Reference

rotateWindow() — fiber Function Reference

Architecture documentation for the rotateWindow() function in limiter_sliding.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  8fb3414b_04a3_af42_a27f_01eb7afedec3["rotateWindow()"]
  91ff16cc_5e69_6619_dbd9_17643ce37c22["limiter_sliding.go"]
  8fb3414b_04a3_af42_a27f_01eb7afedec3 -->|defined in| 91ff16cc_5e69_6619_dbd9_17643ce37c22
  style 8fb3414b_04a3_af42_a27f_01eb7afedec3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/limiter/limiter_sliding.go lines 167–189

func rotateWindow(e *item, ts, expiration uint64) uint64 {
	// Set expiration if entry does not exist
	if e.exp == 0 {
		e.exp = ts + expiration
	} else if ts >= e.exp {
		// The entry has expired, handle the expiration.
		// Reset the current hits to 0.
		elapsed := ts - e.exp
		if elapsed >= expiration {
			e.prevHits = 0
			e.currHits = 0
			e.exp = ts + expiration
		} else {
			e.prevHits = e.currHits
			e.currHits = 0

			e.exp = ts + expiration - elapsed
		}
	}

	// Calculate when it resets in seconds
	return e.exp - ts
}

Subdomains

Frequently Asked Questions

What does rotateWindow() do?
rotateWindow() is a function in the fiber codebase, defined in middleware/limiter/limiter_sliding.go.
Where is rotateWindow() defined?
rotateWindow() is defined in middleware/limiter/limiter_sliding.go at line 167.

Analyze Your Own Codebase

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

Try Supermodel Free