util

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSON format = "json"
	YAML format = "yaml"
)

Variables

View Source
var Version string

Functions

func IsValueInList

func IsValueInList(value string, list []string) bool

func ValidateSections

func ValidateSections(unmarshal func(any) error, i any, whitelist map[string]bool) error

func WhitelistAttrs

func WhitelistAttrs(i any, format format) (map[string]bool, error)

Types

type Command

type Command struct {
	Cmd            *exec.Cmd
	Stdout, Stderr bytes.Buffer
	Err            error
	Status         int
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(name string, arg ...string) *Command

NewCommand builds a context-free command: nothing can interrupt its Run.

Nothing in syver calls it any more, and new code should not. Every internal caller was moved to NewCommandContext because a context-free child has no cancellation and no bound, which under `serve` wedges the health endpoint for the life of the process -- see system/helper_command.go. It stays exported because it is part of the package's published surface.

func NewCommandContext

func NewCommandContext(ctx context.Context, name string, arg ...string) *Command

NewCommandContext is NewCommand with a context attached, so that cancelling the context kills the child process.

Only the `command:` resource needs this, because it is the only caller that imposes a timeout. runCommand (system/command.go) used to return on timeout while leaving the child running and its goroutine parked in Wait: the process was never signalled, so a command that hangs leaked one process and one goroutine every time it ran. Under `serve` that is once per cache refresh for the life of the daemon.

Killing via the context rather than calling Process.Kill from the timeout goroutine avoids racing on Cmd.Process, which Start writes and Wait consumes.

func (*Command) Run

func (c *Command) Run() error

type Config

type Config struct {
	AllowInsecure         bool
	AnnounceToCLI         bool
	Cache                 time.Duration
	Debug                 bool
	Endpoint              string
	FormatOptions         []string
	IgnoreList            []string
	ListenAddress         string
	LocalAddress          string
	LogLevel              string
	MaxConcurrent         int
	Method                string
	NoColor               *bool
	NoFollowRedirects     bool
	OutputFormat          string
	OutputWriter          io.Writer
	PackageManager        string
	Password              string
	RequestBody           string
	Proxy                 string
	RequestHeader         []string
	RequestQueryParams    map[string][]string
	RetryTimeout          time.Duration
	RunLevel              string
	Server                string
	Sleep                 time.Duration
	Spec                  string
	Timeout               time.Duration
	Username              string
	CAFile                string
	CertFile              string
	KeyFile               string
	VarsFiles             []string
	VarsInline            string
	DiscoverSpec          string
	DisabledResourceTypes []string
}

Config is the runtime configuration for the goss system, the cli.Command gets converted to this and it allows other packages to embed goss by creating this structure and using it when adding, validating etc.

NewConfig can be used to create this which will default to what the CLI assumes and allow manipulation via ConfigOption functions

func NewConfig

func NewConfig(opts ...ConfigOption) (rc *Config, err error)

NewConfig creates a default configuration modeled on the defaults the CLI sets, modified using opts

func (*Config) TimeOutMilliSeconds

func (c *Config) TimeOutMilliSeconds() int

TimeOutMilliSeconds is the timeout as milliseconds

type ConfigOption

type ConfigOption func(c *Config) error

ConfigOption manipulates Config

func WithCache

func WithCache(d time.Duration) ConfigOption

WithCache sets how long results may be cached for

func WithColor

func WithColor() ConfigOption

WithColor enables colored output

func WithDebug

func WithDebug() ConfigOption

WithDebug enables debug output

func WithDisabledResourceTypes

func WithDisabledResourceTypes(t ...string) ConfigOption

WithDisabledResourceTypes ensures that any resource matching types listed will be skipped when validating

func WithDiscoverFile

func WithDiscoverFile(f string) ConfigOption

WithDiscoverFile sets a gossfile whose discovery: section runs before the main -g spec

func WithFormatOptions

func WithFormatOptions(opts ...string) ConfigOption

WithFormatOptions sets options used by the output format plugins, valid options are output.WithFormatOptions

func WithMaxConcurrency

func WithMaxConcurrency(mc int) ConfigOption

WithMaxConcurrency is the maximum concurrent test that can be run

func WithNoColor

func WithNoColor() ConfigOption

WithNoColor disables colored output

func WithOutputFormat

func WithOutputFormat(f string) ConfigOption

WithOutputFormat is the formatter to use for output

func WithPackageManager

func WithPackageManager(p string) ConfigOption

WithPackageManager overrides the package manager to use

func WithResultWriter

func WithResultWriter(w io.Writer) ConfigOption

WithResultWriter sets the writer to write output format to when validating

func WithRetryTimeout

func WithRetryTimeout(d time.Duration) ConfigOption

WithRetryTimeout sets the maximum amount of time checks can be retried, it's runtime + WithSleep

func WithSleep

func WithSleep(d time.Duration) ConfigOption

WithSleep sets the time to sleep between retries when WithRetryTimeout is set

func WithSpecFile

func WithSpecFile(f string) ConfigOption

WithSpecFile sets the path to the file holding spec contents

func WithVarsBytes

func WithVarsBytes(v []byte) ConfigOption

WithVarsBytes is a yaml or json byte stream to use as variables passed to the Validator

func WithVarsData

func WithVarsData(v any) ConfigOption

WithVarsData uses v as variables to pass to the Validator

func WithVarsFile

func WithVarsFile(file string) ConfigOption

WithVarsFile is a json or yaml file containing variables to pass to the validator

func WithVarsFiles

func WithVarsFiles(files []string) ConfigOption

WithVarsFiles are json or yaml files containing variables to pass to the validator

func WithVarsString

func WithVarsString(v string) ConfigOption

WithVarsString is a yaml or json string to use as variables passed to the Validator

type OutputConfig

type OutputConfig struct {
	FormatOptions []string
}

Jump to

Keyboard shortcuts

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