flagcheck

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 16 Imported by: ? 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

Overview

Package flagcheck validates the bytes of a flag object with the engine of the relay: the same decoder and the same validity checks the relay applies when it loads a flag file, and that "semaphore-cli lint" applies.

The check is what the relay would do, so a flag that passes here is not dropped at load time. Besides the structural rules of controlplane.ValidateFlags it compiles the targeting queries, checks the percentages, the variations and the rollouts, as the engine does.

The package imports the engine, which is heavy. It is separate from controlplane on purpose: a program that only needs the document format does not pull it in.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("flagcheck: invalid flag file")

ErrInvalid is matched (errors.Is) by every *Error, and by the failure to decode the file.

Functions

func Check

func Check(body []byte, format string) error

Check decodes a flag file in the given format ("yaml", "json" or "toml") with the loader of the relay and validates every flag. It returns nil, an error that matches ErrInvalid and wraps the decoding failure, or an *Error.

Types

type Decoded added in v1.3.0

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

Decoded is a flag file decoded with the loader of the relay, from a tree that was read once, and not yet checked.

func DecodeTree added in v1.3.0

func DecodeTree(tree *controlplane.FlagsTree, entries []controlplane.FlagEntry) (*Decoded, error)

DecodeTree decodes the flags of a tree, as Check decodes the file, a chunk of flags at a time (see controlplane.FlagsTree.DecodeEntries): the time grows with the number of flags. entries are the ones that controlplane.FlagsTree.Entries listed. The error is not meant to be shown: a caller that needs the text of the refusal calls Check. Call it before any other read of the tree that rewrites its nodes.

func (*Decoded) Check added in v1.3.0

func (d *Decoded) Check() error

Check validates every flag as Check does after its decode: nil, or an *Error.

type Error

type Error struct {
	Problems []FlagProblem
}

Error lists the flags that the engine rejects, sorted by flag key.

func (*Error) Error

func (e *Error) Error() string

Error implements error. For each flag it gives the key (a name the operator wrote; made single-line and cut) and the category of the engine's reason, never the text of the engine.

func (*Error) Is

func (*Error) Is(target error) bool

Is reports a match with ErrInvalid.

type FlagProblem

type FlagProblem struct {
	// Err is the reason given by the engine, as it is: it may quote the file (a query, a value), so do not log it
	// where an API key matters. Error() of the *Error does not carry that text.
	Err error
	// Flag is the key of the flag.
	Flag string
}

FlagProblem is one flag that the engine rejects.

func (FlagProblem) Message

func (p FlagProblem) Message() string

Message is the text for one problem: "flag <key>: <category>". It is safe to print and to log: the key, and the category of the engine's reason, never the text of the engine (see Err).

Jump to

Keyboard shortcuts

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