freebie

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Count

type Count uint16

Count is the number of free requests allowed or consumed.

type DB

type DB interface {
	// TakeFreebie atomically checks and consumes the allowance for a
	// request. It returns false without incrementing if none remains.
	// Implementations must be safe for concurrent use.
	TakeFreebie(*http.Request, net.IP) (bool, error)
}

DB is the main interface of the package freebie. It represents a store that keeps track of how many free requests a certain IP address can make to a certain resource.

func NewMemIPMaskStore

func NewMemIPMaskStore(numFreebies Count) DB

NewMemIPMaskStore creates a new in-memory freebie store that masks IP addresses to keep track of free requests. IPv4 addresses are masked to /24 and IPv6 addresses to /48. This reduces risk of abuse by users that have a whole range of IPs at their disposal.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL