model

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 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

Index

Constants

View Source
const (
	SizePattern = `^[1-9][0-9]*(KiB|MiB|GiB)$`

	TimePattern       = `^` + timeFragment + `$`
	TimeOrNonePattern = `^(none|` + timeFragment + `)$`
	PercentPattern    = `^(100|[1-9]?[0-9])%$`
	AgentPattern      = `^[0-9]{1,3}(\.[0-9]{1,3}){3}:[1-9][0-9]{0,4}$`
)

ParseSize, ParseTime, ParsePercent and ParseAgent compile SizePattern, TimeOrNonePattern, PercentPattern and AgentPattern, the same text the schema's "pattern" carries, so the schema and the parser accept the same forms. They differ in three places. No parser compiles TimePattern, and ParseTime accepts "none", so a field whose schema uses TimePattern relies on the schema check alone to refuse "none". A value can match its pattern yet overflow an int64, which only the parser refuses. And an agent can match its pattern, which takes digits and dots, and still hold an octet above 255, an octet with a leading zero or a port above 65535, which only ParseAgent refuses. The two time patterns share timeFragment so their digits and units cannot drift apart.

Variables

This section is empty.

Functions

func FormatSeconds

func FormatSeconds(millis int64) string

FormatSeconds writes a duration the way Envoy reads it: the ProtoJSON form of google.protobuf.Duration, which accepts any number of fractional digits down to nanoseconds, so trailing zeros are dropped. Integer arithmetic keeps the text exact, because a float64 cannot hold every int64 millisecond count. Go's / and % truncate toward zero, so for a negative count both parts carry the sign; it is written once in front and the parts are made positive. The parts are negated rather than millis itself, because -math.MinInt64 does not fit in an int64.

func IsDNSName added in v2.1.0

func IsDNSName(text string) bool

IsDNSName says whether text is an RFC 1123 host name, without a trailing dot and at most 253 characters. A name whose last label is all digits is refused, because RFC 1123 section 2.1 says a host name never has the dotted decimal form: a mistyped IPv4 address such as 10.0.0.256 is then neither an address nor a name, and is refused instead of being looked up.

func ParseAgent

func ParseAgent(text string) (address string, port int64, ok bool)

ParseAgent returns the IPv4 address and the UDP port of an agent written as address:port. The pattern refuses a port of 0 or one with a leading zero, which netip.ParseAddrPort would take; netip refuses what the pattern cannot, an octet above 255 or with a leading zero and a port above 65535.

func ParseEndpoint added in v2.1.0

func ParseEndpoint(text string) (host string, port int64, dns bool, ok bool)

ParseEndpoint returns the host and the port of an endpoint written as host:port, where the host is an IP address or a DNS name; dns is true for a name, which the proxy looks up while it runs. An IPv6 address takes brackets, as netip.ParseAddrPort reads it, and host holds it without them. The port is always written, from 1 to 65535: no collector listens on port 0. A zone is refused, as ParseResolver refuses one.

func ParseKeysURL added in v2.1.0

func ParseKeysURL(text string) (host string, port int64, dns bool, ok bool)

ParseKeysURL returns the host and the port of an auth.jwt.keys URL: https, with no user part, and a host that is an IP address or a DNS name; dns is true for a name, which the proxy looks up while it runs. An IPv6 address takes brackets, which net/url requires, and host holds it without them. The port is 443 when not written, and otherwise from 1 to 65535. A zone is refused, as ParseResolver refuses one.

func ParsePercent

func ParsePercent(text string) (percent int, ok bool)

func ParseResolver added in v2.1.0

func ParseResolver(text string) (address string, port int64, ok bool)

ParseResolver returns the IP address and the port of a name server written as an address with an optional port, 53 when not written. An IPv6 address with a port takes brackets, as netip.ParseAddrPort reads it. Port 0 is refused: no name server answers there. A zone (fe80::1%eth0) is refused: Envoy 1.40.2 aborts on one in a resolver's address when it loads the file (measured).

func ParseSize

func ParseSize(text string) (bytes int64, ok bool)

ParseSize returns the size in bytes. It refuses a size whose byte count does not fit in an int64 instead of letting it wrap to a wrong or negative limit.

func ParseTime

func ParseTime(text string) (millis int64, ok bool)

ParseTime returns the time in milliseconds. "none" is 0: the caller decides what "none" means for the field it fills.

func Reason

func Reason(err error) string

Reason is why a file or directory cannot be read, as a problem words it. The message it goes in names the path already, so the path an os error holds is left out rather than written twice.

func SortProblems

func SortProblems(ps []Problem)

SortProblems orders problems by file, line, column, key path and message. The message is the last key so that two problems at the same position still come out in the same order on every run. A YAML problem has no key path, so YAML problems keep the order they had before the key path existed.

Types

type Auth

type Auth struct {
	Service        Text // the service of `ask`, at the position of `ask`
	Path           string
	Timeout        Time
	Enabled        bool
	Allow          bool // when_unavailable: allow
	OnlyWithHeader string
	Send, Accept   []Header
	SendRequest    bool // send_request: true, which tells the check the request's path, method, scheme and host
}

type Claim added in v2.1.0

type Claim struct {
	Header, Name string
}

Claim is one entry of auth.jwt.claims: the token's claim Name, copied into the request header Header.

type ClientAddress added in v2.1.0

type ClientAddress string

ClientAddress says which address counts as the client's.

const (
	// ClientForwarded is the last address a proxy in front appended to X-Forwarded-For.
	ClientForwarded ClientAddress = "forwarded"
	// ClientConnection is the peer of the TCP connection.
	ClientConnection ClientAddress = "connection"
)

type Count

type Count struct {
	Number int64
	Pos    Pos
}

type Envoy

type Envoy struct {
	Namespace     string // "proxyfile" when not written
	Heap          *Size  // nil when not written
	ConnectBridge bool   // true when not written
}

Envoy is the envoy block: what only the Envoy generator reads.

type Gateway

type Gateway struct {
	Listen            Port
	Admin             *Port
	TLS               *TLS          // nil when not written: the public listener serves plain HTTP
	ClientAddress     ClientAddress // when not written, ClientConnection with TLS and ClientForwarded without
	Limits            Limits
	Timeouts          Timeouts
	Services          []Service // written order
	ServicesPos       Pos       // the `services` key
	Resolver          *Resolver // nil when not written
	Auth              *Auth     // the check, auth.ask; nil when ask is not written
	JWT               *JWT      // auth.jwt; nil when not written
	RemoveFromClients []Header
	Origins           Text    // the origins file as written, absolute or relative to the proxyfile's directory; "" when the proxyfile writes the origins
	Routes            []Route // written order
	RoutesPos         Pos     // the `routes` key
	Log               *Log
	Tracing           *Tracing // nil when neither tracing nor envoy.tracing is written
	Envoy             Envoy
}

Gateway is one proxyfile after reading: every default filled in and every rule checked. Each value a rule or a later stage may name in a problem keeps the position it was written at; a default that was not written has no position, and nothing refuses a default.

func (*Gateway) RPCEntry

func (g *Gateway) RPCEntry() *Route

RPCEntry returns the first `- rpc:` entry of the routes, or nil.

func (*Gateway) Service

func (g *Gateway) Service(name string) *Service

Service returns the service declared with name, or nil.

type Hash added in v2.1.0

type Hash struct {
	Header string
	Client bool // the client's address
	Pos    Pos  // the hash key
}

Hash is what balance hash hashes: exactly one of Header and Client is set.

type Header struct {
	Name   string // without the trailing * of a prefix
	Prefix bool   // written with a trailing *
	Pos    Pos
}

func (Header) Covers added in v2.1.0

func (h Header) Covers(other Header) bool

Covers reports whether the entry h names every header other names: an exact entry covers the one name equal to it, and a prefix entry every name and prefix that starts with it. The early header removal adds no header an entry before it covers, and the reader refuses a claims header an entry of send or accept covers.

type Health added in v2.1.0

type Health struct {
	Path, GRPC         *Text
	Interval, Timeout  Time
	Healthy, Unhealthy int64
	Pos                Pos // the health key
}

Health is the service's active checks. Path and GRPC are nil when not written; GRPC keeps the true for its position, as Route.AuthOff keeps off. Interval, Timeout, Healthy and Unhealthy are 5s, 2s, 2 and 3, without a position, when not written.

type JWT added in v2.1.0

type JWT struct {
	Issuer    string
	Audiences []string // nil for any, which accepts every audience
	// File or URL is set: the keys, as a JSON Web Key Set, in a file on the proxy's host or at an https URL.
	File, URL string
	// Host, Port and DNS describe the URL's host, "" and 0 with a file: an IP address (an IPv6 one without brackets) or a
	// DNS name, which the proxy looks up while it runs; Port is 443 when the URL writes none.
	Host     string
	Port     int64
	DNS      bool
	CA       string  // the CA bundle the URL's certificate must chain to: /etc/ssl/certs/ca-certificates.crt when not written, "" with a file
	Header   string  // the header that carries the token; authorization when not written
	Optional bool    // a request with no token goes through unverified
	Claims   []Claim // written order
}

JWT is auth.jwt: the proxy verifies a signed token on each request itself.

type Limits

type Limits struct {
	Connections    *Count
	RequestHeaders *RequestHeaders
}

type Log

type Log struct {
	StatusFrom    int64
	SamplePercent int
	Pos           Pos // the `log` key
}

type MatchKind

type MatchKind string
const (
	Prefix  MatchKind = "prefix"
	Path    MatchKind = "path"
	Pattern MatchKind = "pattern"
)

type OTel added in v2.1.0

type OTel struct {
	Host        string // the collector's IP address, an IPv6 one without brackets, or its DNS name
	Port        int64
	DNS         bool   // Host is a DNS name, which the proxy looks up while it runs
	Service     string // the service.name the spans carry
	RatePercent int    // 5 when sample.rate is not written
}

OTel is tracing.provider.otel: an OpenTelemetry span for each sampled request, sent as OTLP over gRPC to a collector.

type Port

type Port struct {
	Number int64
	Pos    Pos
}

type Pos

type Pos struct {
	File         string
	Line, Column int
	Path         string // the key path, where the syntax gives no line: services.api.http, routes[1].to
}

Pos is where a problem was found. Line and Column count from 1, so 0 is free to mean "not known". Path places a value whose syntax gives it no line, which is every value of a HOCON file: the HOCON library keeps no position for a value, only for a syntax error.

func (Pos) Where

func (p Pos) Where() string

Where names the position inside a message that points at another place: "on line 8" in YAML, "at routes[0]" in HOCON, whose values have no line.

type Problem

type Problem struct {
	Pos     Pos
	Message string
}

func CannotRead

func CannotRead(path string, err error) Problem

CannotRead is the problem of a file that cannot be read. Every reader of every form reports it with this one text, so a missing file reads the same whichever reader met it.

func FileProblem

func FileProblem(path, message string) []Problem

FileProblem is a problem with the file as a whole, which names no line. It returns a list because every caller returns it alone, as all the problems of its stage.

func (Problem) String

func (p Problem) String() string

String drops the parts of the position that are not known rather than printing a 0 that an editor would read as a real line or column.

type Problems

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

Problems collects the problems of one stage. A stage goes on after a problem, so one run names every problem of it.

func (*Problems) Add

func (p *Problems) Add(pos Pos, format string, args ...any)

func (*Problems) Sorted

func (p *Problems) Sorted() []Problem

Sorted returns the problems in the order every stage reports them in, or nil when there are none.

type Protocol

type Protocol string
const (
	HTTP Protocol = "http"
	GRPC Protocol = "grpc"
)

type RPC

type RPC struct {
	Retries   int64
	RateLimit *RateLimit  // nil when not written; one limit for every RPC route of the entry
	Targets   []RPCTarget // written order
	ToPos     Pos         // the `to` key
}

type RPCTarget

type RPCTarget struct {
	Pattern   string
	Service   Text
	RouteName string // "<service>-rpc" when not written
	Pos       Pos    // the pattern
}

type RateLimit added in v2.1.0

type RateLimit struct {
	Requests, Burst int64
	Per             Time
	ByClient        bool
}

RateLimit is a token bucket: it holds at most Requests + Burst tokens and refills at Requests tokens per Per, and each request takes one. Burst is 0 and ByClient true when not written; ByClient gives each client address a bucket of its own, and false counts every client together.

type RequestHeaders

type RequestHeaders struct {
	Size  Size
	Count Count
}

type Resolver added in v2.1.0

type Resolver struct {
	Address string
	Port    int64 // 53 when not written
}

Resolver is the name server dns.resolver names.

type Route

type Route struct {
	Pos       Pos
	RPC       *RPC // the `- rpc:` entry; the other fields are empty then
	Name      Text
	Match     MatchKind
	Value     Text // the prefix, path or pattern
	Method    string
	To        Text
	Rewrite   *Text
	AuthOff   *Text // the `auth: off` value, kept for its position
	Retries   int64
	RateLimit *RateLimit // nil when not written: the route is never limited
}

Route is one entry of `routes`: the `- rpc:` entry when RPC is set, else a plain route.

type Sample

type Sample struct {
	Default SampleRule
	Rules   []SampleRule // written order
}

Sample is what the sampling manifest holds. The default rule matches every request, so its Host, Method and Path are empty.

type SampleRule

type SampleRule struct {
	Host, Method, Path string // "*" when not written
	First              int64
	RatePercent        int
}

type Service

type Service struct {
	Name string
	Pos  Pos // the service's name
	// Addresses are the backends: address, or 127.0.0.1 when neither address nor addresses is written, as one item,
	// or each of addresses in written order.
	Addresses  []Text
	DNS        bool // Addresses holds one DNS name, which the proxy looks up while it runs
	Balance    Text // "round_robin", without a position, when not written
	Hash       *Hash
	Health     *Health // nil when not written: every backend stays in the pool
	HostHeader string
	Ports      []ServicePort // written order
}

func (*Service) Cluster

func (s *Service) Cluster(p Protocol) string

Cluster names the cluster that carries p to the service, one per protocol: "<name>_<protocol>". Every stage that names a cluster asks here, so no two of them can spell it differently.

func (*Service) Port

func (s *Service) Port(p Protocol) (ServicePort, bool)

Port returns the service's port for p; false when the service has none.

type ServicePort

type ServicePort struct {
	Protocol Protocol
	Number   int64
	Pos      Pos
}

type Size

type Size struct {
	Bytes int64
	Pos   Pos
}

type TLS added in v2.1.0

type TLS struct {
	Certificate, Key string
	ClientsCA        string // "" without tls.clients: no client certificate is asked for
}

TLS is the public listener's certificate and key, and the CA a client's certificate must chain to when tls.clients is written. Each is an absolute path to a PEM file on the proxy's host.

type Tag

type Tag struct {
	Name, Env, Header string
	Default           string // "" when not written; the check refuses an empty one
}

Tag is one custom tag: exactly one of Env and Header is set.

type Text

type Text struct {
	Value string
	Pos   Pos
}

type Time

type Time struct {
	Millis int64 // 0 is none
	Pos    Pos
}

type Timeouts

type Timeouts struct {
	Request, Idle, UpstreamIdle *Time
}

type Tracing

type Tracing struct {
	// XRay and OTel are the provider written: exactly one is set, and envoy.tracing takes XRay alone.
	XRay      *XRay
	OTel      *OTel
	Tags      []Tag // written order
	PathInURL bool
}

Tracing is the tracing key, or envoy.tracing, its old place, which holds the same keys: a trace span for each sampled request.

type XRay

type XRay struct {
	Address string // the agent's IPv4 address; 127.0.0.1 when not written
	Port    int64  // the agent's UDP port; 2000 when not written
	Segment string
	Sample  *Sample // nil when not written: no manifest, and Envoy's own rule applies
}

XRay is tracing.provider.xray: an X-Ray segment for each sampled request, sent to an agent over UDP.

Jump to

Keyboard shortcuts

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