priority

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package priority resolves trusted request importance and propagates it through explicitly selected HTTP destinations. It performs no authentication or I/O.

Index

Constants

View Source
const Header = "X-Gatewise-Priority"

Variables

View Source
var ErrInvalid = errors.New("priority_metadata_invalid")
View Source
var ErrUntrusted = errors.New("priority_metadata_untrusted")

Functions

func Inject

func Inject(r *http.Request)

Inject removes caller metadata and writes only policy-resolved context metadata. The caller must select a trusted outbound destination before calling this.

func With

func With(ctx context.Context, tier, identity string) context.Context

With supplies server-authenticated importance and a stable authenticated actor. Call this only after authentication; identity is never placed in the wire header.

Types

type Cohorts

type Cohorts struct {
	Buckets  int           `json:"buckets"`
	Rotation time.Duration `json:"-"`
	Seed     string        `json:"-"`
}

type Config

type Config struct {
	Tiers                        []Tier
	CriticalTier, BackgroundTier string
	TrustedProxies               []string
	Cohorts                      *Cohorts
}

type Metadata

type Metadata struct {
	Tier   string
	Source string // route_default, context, trusted_http
	Bucket int
	Epoch  int64
	// contains filtered or unexported fields
}

func FromContext

func FromContext(ctx context.Context) (Metadata, bool)

type Policy

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

func New

func New(c Config, maximum int) (*Policy, error)

func (*Policy) Buckets

func (p *Policy) Buckets() int

func (*Policy) Map

func (p *Policy) Map(tier string) string

func (*Policy) Resolve

func (p *Policy) Resolve(r *http.Request, fallback string, now time.Time) (*http.Request, Metadata, error)

func (*Policy) ResolveContext added in v0.8.0

func (p *Policy) ResolveContext(ctx context.Context, fallback string, now time.Time) (context.Context, Metadata, error)

ResolveContext accepts only application-authenticated context metadata. A previously HTTP-resolved context retains its bounded source and cohort key.

func (*Policy) Tiers

func (p *Policy) Tiers() []Tier

func (*Policy) Valid

func (p *Policy) Valid(tier string) bool

type Tier

type Tier struct {
	Name     string `json:"name"`
	Reserved int    `json:"reserved"`
}

type Transport

type Transport struct {
	Base  http.RoundTripper
	Hosts []string
}

Transport propagates only to exact URL Host values (including port) in Hosts. Other destinations have the reserved metadata stripped. Caller requests are cloned. Redirects require the application's normal redirect/security policy as well.

func (Transport) RoundTrip

func (t Transport) RoundTrip(r *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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