gateway

package
v0.28.0 Latest Latest
Warning

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

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

Documentation

Overview

internal/gateway/apikey.go

internal/gateway/gateway.go

internal/gateway/middleware_integration.go

internal/gateway/pipeline.go

internal/gateway/router.go

internal/gateway/validation_example.go

Index

Constants

This section is empty.

Variables

View Source
var CommonValidationRules = map[string]*validation.ValidationRules{
	"artifact-upload": {
		ContentTypes: []string{"application/octet-stream"},
		MaxBodySize:  5 * 1024 * 1024 * 1024,
		Headers: validation.HeaderRules{
			Required: []string{"X-Tenant-ID"},
		},
	},
	"list-artifacts": {
		Query: validation.QueryRules{
			Types: map[string]validation.ParamType{
				"limit": validation.ParamTypeInt,
			},
			Ranges: map[string]validation.Range{
				"limit": {Min: 1, Max: 1000},
			},
		},
	},
}

Example validation rules for common operations

Functions

func ExampleValidationSetup

func ExampleValidationSetup() *validation.RequestValidator

Example of how to use the validation layer

func SetupValidatedRoutes

func SetupValidatedRoutes(r chi.Router)

SetupValidatedRoutes adds validation to your API routes

Types

type APIKey

type APIKey struct {
	Key         string
	TenantID    string
	Permissions []string
	CreatedAt   time.Time
	LastUsed    time.Time
}

APIKey represents an API key with metadata

type APIKeyManager

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

APIKeyManager handles API key validation and permissions

func NewAPIKeyManager

func NewAPIKeyManager() *APIKeyManager

NewAPIKeyManager creates a new API key manager

func (*APIKeyManager) GenerateKey

func (m *APIKeyManager) GenerateKey(tenantID string, permissions []string) string

GenerateKey creates a new API key for a tenant

func (*APIKeyManager) HasPermission

func (m *APIKeyManager) HasPermission(key, permission string) bool

HasPermission checks if a key has a specific permission

func (*APIKeyManager) Middleware

func (m *APIKeyManager) Middleware(next http.Handler) http.Handler

Middleware validates API keys from request headers

func (*APIKeyManager) RevokeKey

func (m *APIKeyManager) RevokeKey(key string) bool

RevokeKey removes an API key

func (*APIKeyManager) ValidateKey

func (m *APIKeyManager) ValidateKey(key string) (bool, string)

ValidateKey checks if a key is valid and returns the tenant ID

type Gateway

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

Gateway handles API routing

func NewGateway

func NewGateway() *Gateway

NewGateway creates a new API gateway

func (*Gateway) HandleFunc

func (g *Gateway) HandleFunc(pattern string, handler http.HandlerFunc)

HandleFunc registers an HTTP handler function for a pattern

func (*Gateway) RegisterRoute

func (g *Gateway) RegisterRoute(pattern, handler string)

RegisterRoute registers a route pattern with a handler name

func (*Gateway) Route

func (g *Gateway) Route(path string) string

Route finds the appropriate handler name for a path

func (*Gateway) ServeHTTP

func (g *Gateway) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler interface

func (*Gateway) WithRateLimit

func (g *Gateway) WithRateLimit(limiter *RateLimiter, handler http.Handler) http.Handler

WithRateLimit adds rate limiting to the gateway

type HeaderTransform

type HeaderTransform struct {
	Add    map[string]string
	Remove []string
}

HeaderTransform adds or removes headers

func (HeaderTransform) Apply

func (ht HeaderTransform) Apply(r *http.Request) *http.Request

Apply implements Transform interface for HeaderTransform

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is a function that wraps an http.Handler

type Pipeline

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

Pipeline manages middleware execution order

func NewPipeline

func NewPipeline() *Pipeline

NewPipeline creates a new middleware pipeline

func (*Pipeline) ServeHTTP

func (p *Pipeline) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP allows Pipeline to be used as an http.Handler

func (*Pipeline) Then

func (p *Pipeline) Then(handler http.Handler) http.Handler

Then wraps the final handler with all middlewares

func (*Pipeline) Use

func (p *Pipeline) Use(middleware Middleware)

Use adds a middleware to the pipeline

type RateLimiter

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

RateLimiter provides rate limiting functionality

func NewRateLimiter

func NewRateLimiter(limit int, window time.Duration) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(key string) bool

Allow checks if a request should be allowed

type Router

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

Router handles request routing and transformation

func NewRouter

func NewRouter() *Router

NewRouter creates a new router

func (*Router) AddBackend

func (r *Router) AddBackend(pattern, backend string)

AddBackend registers a backend for a pattern

func (*Router) AddTransform

func (r *Router) AddTransform(t Transform)

AddTransform adds a transformation to the pipeline

func (*Router) SelectBackend

func (r *Router) SelectBackend(path string) string

SelectBackend chooses the appropriate backend for a path

func (*Router) Transform

func (r *Router) Transform(req *http.Request) *http.Request

Transform applies all transformations to a request

type Transform

type Transform interface {
	Apply(r *http.Request) *http.Request
}

Transform interface for request transformations

type VersionManager

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

VersionManager handles API versioning

func NewVersionManager

func NewVersionManager() *VersionManager

NewVersionManager creates a new version manager

func (*VersionManager) ExtractVersion

func (vm *VersionManager) ExtractVersion(path string) string

ExtractVersion extracts the API version from a path

func (*VersionManager) RegisterHandler

func (vm *VersionManager) RegisterHandler(version string, handler http.Handler)

RegisterHandler registers a handler for a specific version

func (*VersionManager) ServeHTTP

func (vm *VersionManager) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler interface

func (*VersionManager) SetDefaultVersion

func (vm *VersionManager) SetDefaultVersion(version string)

SetDefaultVersion sets the default API version

Directories

Path Synopsis
internal/gateway/cache/middleware.go
internal/gateway/cache/middleware.go
internal/gateway/metrics/collector.go
internal/gateway/metrics/collector.go
internal/gateway/validation/routes.go
internal/gateway/validation/routes.go

Jump to

Keyboard shortcuts

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