ratelimit

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EndpointType

type EndpointType string

EndpointType represents different ServiceNow endpoint types

const (
	EndpointTypeTable      EndpointType = "table"
	EndpointTypeAttachment EndpointType = "attachment"
	EndpointTypeImport     EndpointType = "import"
	EndpointTypeDefault    EndpointType = "default"
)

func DetectEndpointType

func DetectEndpointType(path string) EndpointType

DetectEndpointType attempts to determine the endpoint type from a URL path

type Limiter

type Limiter interface {
	Wait(ctx context.Context) error
	Allow() bool
	Reserve() Reservation
}

Limiter represents a rate limiter interface

type RateLimitError

type RateLimitError struct {
	Message    string
	RetryAfter time.Duration
}

RateLimitError represents a rate limit exceeded error

func NewRateLimitError

func NewRateLimitError(message string, retryAfter time.Duration) *RateLimitError

NewRateLimitError creates a new rate limit error

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type Reservation

type Reservation interface {
	OK() bool
	Delay() time.Duration
	Cancel()
}

Reservation represents a rate limit reservation

type ServiceNowLimiter

type ServiceNowLimiter struct {
	// contains filtered or unexported fields
}

ServiceNowLimiter provides rate limiting specifically for ServiceNow API

func NewServiceNowLimiter

func NewServiceNowLimiter(config ServiceNowLimiterConfig) *ServiceNowLimiter

NewServiceNowLimiter creates a new ServiceNow-specific rate limiter

func (*ServiceNowLimiter) Allow

func (s *ServiceNowLimiter) Allow(endpointType EndpointType) bool

Allow checks if a request can be made immediately to the specified endpoint type

func (*ServiceNowLimiter) Reserve

func (s *ServiceNowLimiter) Reserve(endpointType EndpointType) Reservation

Reserve reserves permission for a future request to the specified endpoint type

func (*ServiceNowLimiter) UpdateConfig

func (s *ServiceNowLimiter) UpdateConfig(config ServiceNowLimiterConfig)

UpdateConfig updates the rate limiting configuration

func (*ServiceNowLimiter) Wait

func (s *ServiceNowLimiter) Wait(ctx context.Context, endpointType EndpointType) error

Wait waits for permission to make a request to the specified endpoint type

type ServiceNowLimiterConfig

type ServiceNowLimiterConfig struct {
	// Requests per second for different endpoint types
	TableRequestsPerSecond      float64
	AttachmentRequestsPerSecond float64
	ImportRequestsPerSecond     float64
	DefaultRequestsPerSecond    float64

	// Burst allowances
	TableBurst      int
	AttachmentBurst int
	ImportBurst     int
	DefaultBurst    int
}

ServiceNowLimiterConfig holds configuration for ServiceNow rate limiting

func DefaultServiceNowConfig

func DefaultServiceNowConfig() ServiceNowLimiterConfig

DefaultServiceNowConfig returns default rate limiting configuration for ServiceNow Based on ServiceNow's documented rate limits

type TokenBucketLimiter

type TokenBucketLimiter struct {
	// contains filtered or unexported fields
}

TokenBucketLimiter implements a token bucket rate limiter

func NewTokenBucketLimiter

func NewTokenBucketLimiter(requestsPerSecond float64, burst int) *TokenBucketLimiter

NewTokenBucketLimiter creates a new token bucket rate limiter

func (*TokenBucketLimiter) Allow

func (t *TokenBucketLimiter) Allow() bool

Allow returns whether a request can be made immediately

func (*TokenBucketLimiter) Reserve

func (t *TokenBucketLimiter) Reserve() Reservation

Reserve reserves a token for a future request

func (*TokenBucketLimiter) Wait

func (t *TokenBucketLimiter) Wait(ctx context.Context) error

Wait blocks until the rate limiter allows a request

Jump to

Keyboard shortcuts

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