document

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 10 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 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

View Source
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.

View Source
const SchemaVersion = 1

SchemaVersion is the only document version this package parses.

Variables

BuiltinOperators lists the built-in operators without their negations.

Functions

func BaseOperator

func BaseOperator(op string) (base string, negated bool, ok bool)

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

func JSONInt64(n json.Number) (int64, bool)

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 Attribute

type Attribute struct {
	Type        Type   `json:"type"`
	Description string `json:"description,omitempty"`
}

Attribute is one attribute callers may send.

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

func ParseCatalog(data []byte) (*Catalog, error)

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

func (c *Catalog) UnmarshalJSON(data []byte) error

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

func ParseFlags(data []byte) (*Flags, error)

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

func (d *Flags) UnmarshalJSON(data []byte) error

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

type Rollout struct {
	Percentage int    `json:"percentage"`
	BucketBy   string `json:"bucket_by"`
}

Rollout limits a rule to a stable percentage of callers, bucketed by the value of the BucketBy attribute.

func (*Rollout) UnmarshalJSON

func (r *Rollout) UnmarshalJSON(data []byte) error

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.

type Type

type Type string

Type is the declared type of an attribute or of a custom operator's value.

const (
	TypeString  Type = "string"
	TypeInteger Type = "integer"
	TypeNumber  Type = "number"
	TypeBoolean Type = "boolean"
)

Jump to

Keyboard shortcuts

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