Documentation
¶
Overview ¶
Package document defines schema_version 1 of the two documents stored in AWS AppConfig: the feature-flags document (flags and groups) and the project catalog (attributes, custom operators and resolvers).
The embedded JSON Schemas check the shape of each document. Checks that cross references (a group exists, an attribute is in the catalog, value types) belong to Validate, not to the schemas or to the parsers here.
Index ¶
- Constants
- Variables
- func BaseOperator(op string) (base string, negated bool, ok bool)
- func CatalogSchema() []byte
- func FlagsSchema() []byte
- func JSONInt64(n json.Number) (int64, bool)
- type Attribute
- type Catalog
- type Condition
- type Flag
- type Flags
- type Group
- type Operator
- type Resolver
- type Rollout
- type Rule
- type Type
Constants ¶
const ( OpEq = "eq" OpIn = "in" OpInGroup = "in_group" OpGt = "gt" OpLt = "lt" OpStartsWith = "starts_with" OpMatches = "matches" OpContains = "contains" OpExists = "exists" NegationPrefix = "not_" )
Built-in operators. Each also has a negated form with the NegationPrefix (not_eq, not_in_group, ...). Catalog custom operators may not reuse any of these names.
const SchemaVersion = 1
SchemaVersion is the only document version this package parses.
Variables ¶
var BuiltinOperators = []string{ OpEq, OpIn, OpInGroup, OpGt, OpLt, OpStartsWith, OpMatches, OpContains, OpExists, }
BuiltinOperators lists the built-in operators without their negations.
Functions ¶
func BaseOperator ¶
BaseOperator strips the negation from a built-in operator name. ok is false when op is not a built-in operator or its negation.
func CatalogSchema ¶
func CatalogSchema() []byte
CatalogSchema returns the draft-04 JSON Schema of the catalog document.
func FlagsSchema ¶
func FlagsSchema() []byte
FlagsSchema returns the draft-04 JSON Schema of the feature-flags document.
func JSONInt64 ¶
JSONInt64 reads a JSON number as an int64 if it is exactly one, without rounding through float64: "1.0", "1e3" and "9007199254740993.0" are; "1.5" and anything outside int64 are not. Literals longer than 100 characters or with an exponent beyond ±30 are rejected before any exact parsing, so hostile input stays cheap.
Types ¶
type Catalog ¶
type Catalog struct {
SchemaVersion int `json:"schema_version"`
Attributes map[string]Attribute `json:"attributes"`
Operators map[string]Operator `json:"operators,omitempty"`
Resolvers map[string]Resolver `json:"resolvers,omitempty"`
}
Catalog declares what a project's flags may use: attributes with their types, custom operators and attribute resolvers. It lives in the project repository and is published to AppConfig by CI.
func ParseCatalog ¶
ParseCatalog decodes a catalog document. It rejects unknown fields and any schema_version other than SchemaVersion; it does not apply the JSON Schema or check references.
func (*Catalog) UnmarshalJSON ¶
UnmarshalJSON decodes a Catalog strictly, accepting schema_version written as any integral number.
type Condition ¶
type Condition struct {
Attr string `json:"attr"`
Op string `json:"op"`
Value any `json:"value,omitempty"`
}
Condition compares one attribute with Value using Op, a built-in or a custom operator declared in the catalog. Value is absent for exists and not_exists, a list for in and not_in, and a single value otherwise.
type Flag ¶
type Flag struct {
Description string `json:"description,omitempty"`
Owner string `json:"owner"`
Jira string `json:"jira"`
RemoveAfter string `json:"remove_after"`
Enabled bool `json:"enabled"`
Rules []Rule `json:"rules,omitempty"`
Default bool `json:"default"`
}
Flag is one flag. When Enabled is false (kill switch) the flag is off for every caller and its rules are skipped. Otherwise the first matching rule decides, and Default applies when none matches.
type Flags ¶
type Flags struct {
SchemaVersion int `json:"schema_version"`
Groups map[string]Group `json:"groups,omitempty"`
Flags map[string]Flag `json:"flags"`
}
Flags is the feature-flags document: every flag and group of one project in one AppConfig hosted version, so a group and the rule using it always deploy together.
func ParseFlags ¶
ParseFlags decodes a feature-flags document. It rejects unknown fields and any schema_version other than SchemaVersion; it does not apply the JSON Schema or check references.
func (*Flags) UnmarshalJSON ¶
UnmarshalJSON decodes Flags strictly, accepting schema_version written as any integral number.
type Group ¶
type Group struct {
Attr string `json:"attr"`
Description string `json:"description,omitempty"`
Values []any `json:"values"`
}
Group is a named list of up to 200 values of one attribute.
type Operator ¶
type Operator struct {
ValueType Type `json:"value_type"`
Description string `json:"description,omitempty"`
}
Operator is a custom operator registered in code; ValueType is the type of the condition value it takes.
type Resolver ¶
type Resolver struct {
Requires []string `json:"requires,omitempty"`
Description string `json:"description,omitempty"`
}
Resolver fetches the attribute it is keyed by when a rule needs it and the caller did not send it. Requires lists the attributes it reads.
type Rollout ¶
Rollout limits a rule to a stable percentage of callers, bucketed by the value of the BucketBy attribute.
func (*Rollout) UnmarshalJSON ¶
UnmarshalJSON decodes a Rollout strictly, accepting percentage written as any integral number.
type Rule ¶
type Rule struct {
Name string `json:"name"`
If []Condition `json:"if"`
Then bool `json:"then"`
Rollout *Rollout `json:"rollout,omitempty"`
}
Rule matches when every condition in If holds; an empty If matches every caller. Without Rollout all matching callers get Then. With Rollout only the given percentage of them get Then, and the rest do not match the rule, so evaluation continues with the next rule.