gateway

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const MetadataLegacyTeamIDKey = "team_id"

MetadataLegacyTeamIDKey is the pre-tenant client key. It is never persisted: callers that still send it have their value dropped so tenant partitioning relies solely on the server-stamped tenant_id.

View Source
const MetadataTenantIDKey = "tenant_id"
View Source
const TierFree = ratelimit.TierFree

Variables

View Source
var (
	ErrNotFound      = fmt.Errorf("gateway: %w", commonerrors.ErrNotFound)
	ErrAlreadyExists = fmt.Errorf("gateway: %w", commonerrors.ErrAlreadyExists)
	ErrHasDependents = fmt.Errorf("gateway: %w", commonerrors.ErrHasDependents)
	ErrInvalidDomain = fmt.Errorf("gateway: invalid domain: %w", commonerrors.ErrValidation)
)

Sentinel errors for the gateway aggregate. They wrap the package-wide sentinels in pkg/common/errors so callers can match either the generic or the entity-specific error via errors.Is.

Functions

func IsValidSlug

func IsValidSlug(slug string) bool

func NewSlug added in v0.3.4

func NewSlug() (string, error)

NewSlug returns a random gateway slug that satisfies the DNS-label format (e.g. "gw-k3f9x1a2b7c4"). 36^12 combinations make collisions vanishingly rare; the slug unique index plus a retry on save covers the residual risk.

func NormalizeDomain

func NormalizeDomain(domain string) (string, error)

func NormalizeSlug

func NormalizeSlug(slug string) string

func SanitizeClientMetadata added in v0.3.4

func SanitizeClientMetadata(metadata map[string]string) map[string]string

func ValidateTier added in v0.8.0

func ValidateTier(tier string) (string, error)

ValidateTier normalizes tier and rejects unknown plan labels; empty means free.

func WithTenantID added in v0.3.4

func WithTenantID(metadata map[string]string, tenantID string) map[string]string

Types

type ClientTLSConfig

type ClientTLSConfig map[string]json.RawMessage

func (*ClientTLSConfig) Scan

func (c *ClientTLSConfig) Scan(value interface{}) error

func (ClientTLSConfig) Value

func (c ClientTLSConfig) Value() (driver.Value, error)

type Entitlements added in v0.8.0

type Entitlements struct {
	Tier          string `json:"tier"`
	BurstPerMin   *int   `json:"burst_per_min,omitempty"`
	QuotaPerMonth *int   `json:"quota_per_month,omitempty"`
	MaxInstances  *int   `json:"max_instances,omitempty"`
}

Entitlements is the plan label plus caps stamped by the control plane. Numeric caps are required for rate-limit enforcement (no built-in catalog).

func DefaultEntitlements added in v0.8.0

func DefaultEntitlements() Entitlements

func NormalizeEntitlements added in v0.18.0

func NormalizeEntitlements(e Entitlements) (Entitlements, error)

NormalizeEntitlements validates tier and requires stamped caps when any limit field is present; API payloads that include entitlements should send all three caps (control-plane stamp).

func RequireStampedEntitlements added in v0.18.0

func RequireStampedEntitlements(e Entitlements) (Entitlements, error)

RequireStampedEntitlements is used when the control plane sends an entitlements object (upgrade/downgrade scripts).

func (Entitlements) HasStampedLimits added in v0.18.0

func (e Entitlements) HasStampedLimits() bool

HasStampedLimits reports whether all three numeric caps were stamped together.

func (Entitlements) ResolveLimits added in v0.18.0

func (e Entitlements) ResolveLimits() (ratelimit.Limits, bool)

ResolveLimits returns stamped caps only. Unstamped instances have no commercial plan metering.

type Gateway

type Gateway struct {
	ID              ids.GatewayID        `json:"id"`
	Slug            string               `json:"slug"`
	Status          string               `json:"status"`
	Domain          string               `json:"domain,omitempty"`
	Metadata        map[string]string    `json:"metadata,omitempty"`
	Telemetry       *telemetry.Telemetry `json:"telemetry,omitempty"`
	ClientTLSConfig ClientTLSConfig      `json:"client_tls,omitempty"`
	SessionConfig   *SessionConfig       `json:"session_config,omitempty"`
	Entitlements    Entitlements         `json:"entitlements"`
	CreatedAt       time.Time            `json:"created_at"`
	UpdatedAt       time.Time            `json:"updated_at"`
}

func New

func New(slug string) (*Gateway, error)

func Rehydrate

func Rehydrate(
	id ids.GatewayID,
	slug, status, domain string,
	tel *telemetry.Telemetry,
	clientTLS ClientTLSConfig,
	session *SessionConfig,
	createdAt, updatedAt time.Time,
) *Gateway

func (*Gateway) TenantID added in v0.3.4

func (g *Gateway) TenantID() string

func (*Gateway) Validate

func (g *Gateway) Validate() error

type ListFilter

type ListFilter struct {
	SlugContains string
	// TenantID scopes results to one tenant; empty means no tenant filter (platform-wide).
	TenantID string
	Page     int
	Size     int
}

type Repository

type Repository interface {
	Save(ctx context.Context, g *Gateway) error
	Update(ctx context.Context, g *Gateway) error
	Delete(ctx context.Context, id ids.GatewayID) error
	FindByID(ctx context.Context, id ids.GatewayID) (*Gateway, error)
	FindByDomain(ctx context.Context, domain string) (*Gateway, error)
	FindBySlug(ctx context.Context, slug string) (*Gateway, error)
	List(ctx context.Context, filter ListFilter) (items []*Gateway, total int, err error)
	CountByTenantID(ctx context.Context, tenantID string) (int, error)
	// SaveWithTenantCap atomically enforces maxInstances for tenantID before inserting g; maxInstances <= 0 means unlimited.
	SaveWithTenantCap(ctx context.Context, g *Gateway, tenantID string, maxInstances int) error
	// UpdateWithTenantCap updates g under the same tenant advisory lock used by SaveWithTenantCap when maxInstances > 0.
	UpdateWithTenantCap(ctx context.Context, g *Gateway, tenantID string, maxInstances int) error
}

type SessionConfig

type SessionConfig struct {
	Enabled       *bool  `json:"enabled,omitempty"`
	HeaderName    string `json:"header_name,omitempty"`
	BodyParamName string `json:"body_param_name,omitempty"`
}

func DefaultSessionConfig

func DefaultSessionConfig() *SessionConfig

func (*SessionConfig) IsEnabled

func (s *SessionConfig) IsEnabled() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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