gateway

package
v0.0.0-...-46646b9 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gateway

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

Gateway represents an API gateway

func NewGateway

func NewGateway(config *GatewayConfig, logger *slog.Logger) (*Gateway, error)

NewGateway creates a new API gateway

func (*Gateway) AddRoute

func (gw *Gateway) AddRoute(config RouteConfig) error

AddRoute adds a new route to the gateway

func (*Gateway) GetStats

func (gw *Gateway) GetStats() *GatewayStats

GetStats returns gateway statistics

func (*Gateway) ListRoutes

func (gw *Gateway) ListRoutes() map[string]*Route

ListRoutes returns all configured routes

func (*Gateway) RemoveRoute

func (gw *Gateway) RemoveRoute(path string)

RemoveRoute removes a route from the gateway

func (*Gateway) Start

func (gw *Gateway) Start() error

Start starts the API gateway

func (*Gateway) Stop

func (gw *Gateway) Stop(ctx context.Context) error

Stop stops the API gateway

func (*Gateway) Use

func (gw *Gateway) Use(middleware MiddlewareFunc)

Use adds middleware to the gateway

type GatewayConfig

type GatewayConfig struct {
	Name            string
	ListenAddr      string
	UpstreamTimeout time.Duration
	MaxRetries      int
	RetryDelay      time.Duration
	RateLimitConfig *ratelimit.RateLimitConfig
	Routes          []RouteConfig
}

GatewayConfig holds the configuration for the API gateway

type GatewayStats

type GatewayStats struct {
	TotalRequests       int64
	SuccessfulRequests  int64
	FailedRequests      int64
	AverageResponseTime time.Duration
	LastRequestTime     time.Time
	RouteStats          map[string]*RouteStats
}

GatewayStats holds gateway statistics

type MiddlewareFunc

type MiddlewareFunc func(http.Handler) http.Handler

MiddlewareFunc represents a middleware function

type RewriteRule

type RewriteRule struct {
	Pattern string `json:"pattern"`
	Replace string `json:"replace"`
}

RewriteRule defines a URL rewrite rule

type Route

type Route struct {
	Path         string
	Methods      map[string]bool
	UpstreamURL  *url.URL
	StripPrefix  string
	AddHeaders   map[string]string
	Transform    *TransformConfig
	RewriteRules []RewriteRule
}

Route represents a configured route

type RouteConfig

type RouteConfig struct {
	Path         string            `json:"path"`
	Methods      []string          `json:"methods"`
	UpstreamURL  string            `json:"upstream_url"`
	StripPrefix  string            `json:"strip_prefix,omitempty"`
	AddHeaders   map[string]string `json:"add_headers,omitempty"`
	Transform    *TransformConfig  `json:"transform,omitempty"`
	RewriteRules []RewriteRule     `json:"rewrite_rules,omitempty"`
}

RouteConfig defines a route configuration

type RouteStats

type RouteStats struct {
	RequestCount        int64
	SuccessCount        int64
	ErrorCount          int64
	AverageResponseTime time.Duration
	LastRequestTime     time.Time
}

RouteStats holds statistics for a specific route

type TransformConfig

type TransformConfig struct {
	Request  *TransformRule `json:"request,omitempty"`
	Response *TransformRule `json:"response,omitempty"`
}

TransformConfig defines request/response transformation rules

type TransformRule

type TransformRule struct {
	AddFields    map[string]interface{} `json:"add_fields,omitempty"`
	RemoveFields []string               `json:"remove_fields,omitempty"`
	RenameFields map[string]string      `json:"rename_fields,omitempty"`
	FilterFields []string               `json:"filter_fields,omitempty"`
}

TransformRule defines a transformation rule

Jump to

Keyboard shortcuts

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