Documentation
¶
Index ¶
- Constants
- func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error)
- func ReadUserIP(r *http.Request) string
- type Cache
- func (c Cache) Add(k string, x bool, d time.Duration) error
- func (c Cache) Delete(k string)
- func (c Cache) DeleteExpired()
- func (c Cache) DeleteLeastRecent(maxSize int)
- func (c Cache) Flush()
- func (c Cache) Get(k string) (bool, bool)
- func (c Cache) GetWithExpiration(k string) (interface{}, time.Time, bool)
- func (c Cache) Has(k string) bool
- func (c Cache) ItemCount() int
- func (c Cache) Items() map[string]Item
- func (c Cache) Load(r io.Reader) error
- func (c Cache) LoadFile(fname string) error
- func (c Cache) OnEvicted(f func(string, bool))
- func (c Cache) Replace(k string, x bool, d time.Duration) error
- func (c Cache) Save(w io.Writer) (err error)
- func (c Cache) SaveFile(fname string) error
- func (c Cache) Set(k string, x bool, d time.Duration)
- func (c Cache) SetDefault(k string, x bool)
- type Config
- type ICalMiddleware
- type Item
- type LogLevel
- type RequestMultiplexer
Constants ¶
const ( // NoExpiration indicates that the item never expires NoExpiration time.Duration = -1 // DefaultExpiration indicates to use the default expiration time DefaultExpiration time.Duration = 0 )
Variables ¶
This section is empty.
Functions ¶
func ReadUserIP ¶ added in v0.0.2
ReadUserIP extracts the user's IP address from the request
Types ¶
type Cache ¶ added in v0.0.2
type Cache struct {
// contains filtered or unexported fields
}
Cache is the main cache structure
func NewCache ¶ added in v0.0.2
NewCache creates a new cache with the given expiration and cleanup interval
func NewFrom ¶ added in v0.0.2
NewFrom creates a new cache with the given expiration, cleanup interval, and items
func (Cache) Delete ¶ added in v0.0.2
func (c Cache) Delete(k string)
Delete removes an item from the cache
func (Cache) DeleteExpired ¶ added in v0.0.2
func (c Cache) DeleteExpired()
DeleteExpired deletes all expired items from the cache
func (Cache) DeleteLeastRecent ¶ added in v0.0.8
func (c Cache) DeleteLeastRecent(maxSize int)
DeleteLeastRecent removes the least recently accessed items when the cache exceeds the given size
func (Cache) GetWithExpiration ¶ added in v0.0.2
GetWithExpiration retrieves an item and its expiration time
func (Cache) ItemCount ¶ added in v0.0.2
func (c Cache) ItemCount() int
ItemCount returns the number of items in the cache
func (Cache) SetDefault ¶ added in v0.0.2
SetDefault adds an item to the cache with the default expiration
type Config ¶
type Config struct {
ForwardToken bool `json:"forwardToken,omitempty" yaml:"forwardToken,omitempty" toml:"forwardToken,omitempty"`
Freshness int64 `json:"freshness,omitempty" yaml:"freshness,omitempty" toml:"freshness,omitempty"`
HeaderName string `json:"headerName,omitempty" yaml:"headerName,omitempty" toml:"headerName,omitempty"`
AllowSubnet []string `json:"allowSubnet,omitempty" yaml:"allowSubnet,omitempty" toml:"allowSubnet,omitempty"`
Timeout int64 `json:"timeout,omitempty" yaml:"timeout,omitempty" toml:"timeout,omitempty"`
GlobalRateLimit int `json:"globalRateLimit,omitempty" yaml:"globalRateLimit,omitempty" toml:"globalRateLimit,omitempty"`
PerIPRateLimit int `json:"perIPRateLimit,omitempty" yaml:"perIPRateLimit,omitempty" toml:"perIPRateLimit,omitempty"`
RateLimitWindow int64 `json:"rateLimitWindow,omitempty" yaml:"rateLimitWindow,omitempty" toml:"rateLimitWindow,omitempty"`
LogLevel string `json:"logLevel,omitempty" yaml:"logLevel,omitempty" toml:"logLevel,omitempty"`
CleanupInterval int64 `json:"cleanupInterval,omitempty" yaml:"cleanupInterval,omitempty" toml:"cleanupInterval,omitempty"`
UpstreamURL string `json:"upstreamURL,omitempty" yaml:"upstreamURL,omitempty" toml:"upstreamURL,omitempty"`
}
Config represents the middleware configuration
type ICalMiddleware ¶
type ICalMiddleware struct {
// contains filtered or unexported fields
}
ICalMiddleware is the main middleware struct
func (*ICalMiddleware) ServeHTTP ¶
func (plugin *ICalMiddleware) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP handles the HTTP request
type Item ¶ added in v0.0.2
type Item struct {
Object bool // The cached value
Expiration int64 // When the item expires (Unix nano time)
LastAccess time.Time // When the item was last accessed
}
Item represents a cache item
type RequestMultiplexer ¶ added in v0.0.8
type RequestMultiplexer struct {
// contains filtered or unexported fields
}
RequestMultiplexer represents an in-flight request for a specific token