Documentation
¶
Index ¶
- func IsRemediable(err error) bool
- func NewRemediableErr(err, remediation string) error
- func Remediation(err error) string
- func Unwrap(err error) []error
- func WithRemediation(err error, remediation string) error
- type ChannelReader
- type Colorer
- func (c Colorer) Black(m string) string
- func (c Colorer) Blue(m string) string
- func (c Colorer) Bold(m string) string
- func (c Colorer) Cyan(m string) string
- func (c Colorer) Green(m string) string
- func (c Colorer) Grey(m string) string
- func (c Colorer) Magenta(m string) string
- func (c Colorer) Red(m string) string
- func (c Colorer) Underline(m string) string
- func (c Colorer) Yellow(m string) string
- type FileCapture
- type Informer
- type LineReader
- type NoOpInformer
- type Printer
- type PrinterOpt
- type PrinterWithStdCapture
- type Remediable
- type Runner
- type RunnerConfig
- type RunnerOpt
- type Validatable
- type Validate
- type Validation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsRemediable ¶
IsRemediable checks if an error has a remediation.
func NewRemediableErr ¶
NewRemediableErr returns a new Remediable error.
func Remediation ¶
Remediation returns the Remediation message for an error if it has it. Otherwise it returns an empty string.
func Unwrap ¶
Unwrap unfolds and flattens errors if err implements Unwrap []error. If it doesn't implement it, it just returns a slice with one single error.
func WithRemediation ¶
WithRemediation makes an error Remediable.
Types ¶
type ChannelReader ¶
type ChannelReader struct {
// contains filtered or unexported fields
}
ChannelReader implements LineReader for a channel of strings source.
func NewChannelReader ¶
func NewChannelReader(in <-chan string, name string) ChannelReader
NewChannelReader returns a new ChannelReader.
func (ChannelReader) Line ¶
func (c ChannelReader) Line() (string, bool)
Line reads a line from the channel. Returns false if there is no more lines to read (in buffered channels) or the channel is closed.
func (ChannelReader) Name ¶
func (c ChannelReader) Name() string
type FileCapture ¶
FileCapture forwards the content of a file to a channel, reading line by line.
func NewFileCapture ¶
func NewFileCapture(out chan<- string) *FileCapture
NewFileCapture returns a new FileCapture.
func (*FileCapture) Close ¶
func (r *FileCapture) Close() error
Close closes all internal resources and stops routines.
func (*FileCapture) Init ¶
func (r *FileCapture) Init() error
Init initializes the FileCapture. The caller is responsible for calling Close after Init succeeds once they are done with the FileCapture. If not, FileCapture might leak resources.
type LineReader ¶
type LineReader interface {
// Line reads a line from the source. It returns false for the second argument
// if there is no more lines to read.
Line() (string, bool)
// Name is name of the lines source.
Name() string
}
LineReader is an interface that allows to read lines from some source.
type NoOpInformer ¶
type NoOpInformer struct{}
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Informer is an informer that prints the validation steps to stdout.
func NewPrinter ¶
func NewPrinter(opts ...PrinterOpt) Printer
type PrinterOpt ¶
type PrinterOpt func(*Printer)
PrinterOpt allows to configure the Printer.
func WithExternalLogs ¶
func WithExternalLogs(in LineReader) PrinterOpt
WithExternalLogs allows to configure an external source of logs that will get included in the output when a validation fails. This is useful for correctly displaying the output of external processes that are invoked during the validation. You can just capture their output and let the printer handle its display.
func WithOutWriter ¶
func WithOutWriter(out io.Writer) PrinterOpt
WithOutWriter allows to configure the output destination.
type PrinterWithStdCapture ¶
type PrinterWithStdCapture struct {
Printer
FileCapture
}
PrinterWithStdCapture is a convenience struct that combines a Printer and a FileCapture, allowing to capture a os.File. Useful for capturing stderr or stdout and displaying it through the Printer.
func NewPrinterWithStdCapture ¶
func NewPrinterWithStdCapture(stdName string) *PrinterWithStdCapture
NewPrinterWithStdCapture returns a new PrinterWithStdCapture.
type Remediable ¶
type Remediable interface {
Remediation() string
}
Remediable is an error that provides a possible remediation.
type Runner ¶
type Runner[O Validatable[O]] struct { // contains filtered or unexported fields }
Runner allows to compose and run validations.
func NewRunner ¶
func NewRunner[O Validatable[O]](informer Informer, opts ...RunnerOpt) *Runner[O]
NewRunner constructs a new Runner.
func (*Runner[O]) Register ¶
func (r *Runner[O]) Register(validations ...Validation[O])
Register adds validations to the Runner.
func (*Runner[O]) Sequentially ¶
Sequentially runs all validations one after the other and waits until they all finish, aggregating the errors if present. obj must not be modified. If it is, this indicates a programming error and the method will panic.
func (*Runner[O]) UntilError ¶
func (r *Runner[O]) UntilError(validations ...Validation[O]) Validation[O]
type RunnerConfig ¶
type RunnerConfig struct {
// contains filtered or unexported fields
}
RunnerConfig holds the configuration for the Runner.
type RunnerOpt ¶
type RunnerOpt func(*RunnerConfig)
RunnerOpt allows to configure the Runner.
func WithSkipValidations ¶
WithSkipValidation configures the runner to skip the validations with the given names.
type Validatable ¶
type Validatable[O any] interface { DeepCopy() O }
Validatable is anything that can be validated.
type Validate ¶
type Validate[O Validatable[O]] func(ctx context.Context, informer Informer, obj O) error
Validate is the logic for a validation of a type O.
func UntilError ¶
func UntilError[O Validatable[O]](validates ...Validate[O]) Validate[O]
UntilError returns a composed validate that runs all validations until one fails.
type Validation ¶
type Validation[O Validatable[O]] struct { Name string Validate Validate[O] }
Validation validates the system for a type O.
func New ¶
func New[O Validatable[O]](name string, validate Validate[O]) Validation[O]