Documentation
¶
Index ¶
- Constants
- func FormatSeconds(millis int64) string
- func ParsePercent(text string) (percent int, ok bool)
- func ParseSize(text string) (bytes int64, ok bool)
- func ParseTime(text string) (millis int64, ok bool)
- func SortProblems(ps []Problem)
- type Auth
- type Count
- type Gateway
- type Header
- type Limits
- type Log
- type MatchKind
- type Port
- type Pos
- type Problem
- type Problems
- type Protocol
- type RPC
- type RPCTarget
- type RequestHeaders
- type Route
- type Service
- type ServicePort
- type Size
- type Text
- type Time
- type Timeouts
Constants ¶
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 ¶
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 ParseSize ¶
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 ¶
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 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.
type Limits ¶
type Limits struct {
Heap *Size
Connections *Count
RequestHeaders *RequestHeaders
}
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.
type Problem ¶
func CannotRead ¶ added in v1.1.0
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 ¶
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.
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.
type RequestHeaders ¶
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
}