Documentation ¶
Index ¶
- Variables
- func ActivateAPIKey(keyID string) error
- func Init(cfg Config) error
- func Initialize(db *sql.DB, prefix string, byteLength int) error
- func IsRootKey(cfg MiddlewareConfig) func(http.Handler) http.Handler
- func RevokeAPIKey(keyID string) error
- func SetupTables(db *sql.DB) error
- func UpdateAPIKeyRestrictions(keyID string, restrictions APIKey) error
- func ValidateAPIKey(cfg MiddlewareConfig) func(http.Handler) http.Handler
- type APIKey
- type ActivityLog
- type Config
- type ErrorResponse
- type Metrics
- type MiddlewareConfig
- type RateLimiter
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrAPIKeyNotFound = errors.New("API key not found") ErrInvalidAPIKey = errors.New("invalid API key") ErrExpiredAPIKey = errors.New("expired API key") ErrLimitUsageExceeded = errors.New("API key limit usage exceeded") ErrRateLimitExceeded = errors.New("rate limit exceeded") ErrInsufficientPrivileges = errors.New("insufficient privileges") ErrInvalidAPIKeyID = errors.New("invalid API key ID format") ErrMissingAPIKeyOrID = errors.New("missing api key or id") ErrInternalServerError = errors.New("internal server error") ErrIPNotAllowed = errors.New("ip not allowed") ErrFailedToVerifyRootKey = errors.New("failed to verify root key") )
Functions ¶
func ActivateAPIKey ¶
ActivateAPIKey activates a previously revoked API key
func Initialize ¶
Initialize sets up the necessary tables and generates a root key if not already initialized
func SetupTables ¶
SetupTables creates necessary tables in the database
func UpdateAPIKeyRestrictions ¶
UpdateAPIKeyRestrictions updates the restrictions for an API key
func ValidateAPIKey ¶
func ValidateAPIKey(cfg MiddlewareConfig) func(http.Handler) http.Handler
Types ¶
type APIKey ¶
type APIKey struct { ID string Key string CreatedAt time.Time ExpiresAt *time.Time IsActive bool IsRoot bool AllowedIPs []string AllowedCountries []string CORSAllowedOrigins []string RateLimit *int LimitUse *int }
APIKey represents an API key in the system
func CreateAPIKey ¶
CreateAPIKey creates a new API key
type ActivityLog ¶
type ActivityLog struct { ID string APIKeyID string Timestamp time.Time UserAgent string IPAddress string Region string }
ActivityLog represents a log entry for API key usage
type ErrorResponse ¶
type ErrorResponse func(w http.ResponseWriter, message string, statusCode int)
type Metrics ¶
type Metrics struct { APIKeyID string ExpiresAt *time.Time RemainingUses *int LastUsage time.Time SuccessCount int InvalidCount int TotalAccess int }
Metrics represents usage metrics for an API key
func GetMetrics ¶
GetMetrics retrieves usage metrics for an API key
type MiddlewareConfig ¶
type MiddlewareConfig struct { APIIDHeaderName string APIKeyHeaderName string HeaderPrefix string ErrorHandler ErrorResponse }
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
func NewRateLimiter ¶
func NewRateLimiter() *RateLimiter
Source Files ¶
Click to show internal directories.
Click to hide internal directories.