model

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 9 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])%$`
)

ParseSize, ParseTime and ParsePercent compile SizePattern, TimeOrNonePattern and PercentPattern, the same text the schema's "pattern" carries, so the schema and the parser accept the same forms. They differ in two 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". And a value can match its pattern yet overflow an int64, which only the parser 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 ParsePercent

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

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 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
}

type Count

type Count struct {
	Number int64
	Pos    Pos
}

type Gateway

type Gateway struct {
	Namespace         string // "proxyfile" when not written
	Listen            Port
	Admin             *Port
	Limits            Limits
	Timeouts          Timeouts
	Services          []Service // written order
	ServicesPos       Pos       // the `services` key
	Auth              *Auth
	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
}

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 Header struct {
	Name   string // without the trailing * of a prefix
	Prefix bool   // written with a trailing *
	Pos    Pos
}

type Limits

type Limits struct {
	Heap           *Size
	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 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 added in v1.1.0

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 added in v1.1.0

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. The problem already starts with the path, so the path an os error holds is left out rather than written twice.

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
	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 RequestHeaders

type RequestHeaders struct {
	Size  Size
	Count Count
}

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
}

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

type Service

type Service struct {
	Name       string
	Pos        Pos  // the service's name
	Address    Text // "127.0.0.1" when not written
	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 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
}

Jump to

Keyboard shortcuts

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