config

package
v0.0.0-...-efab62b Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2016 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatCSV      OutputFormat = "CSV"
	FormatTAB                   = "TAB"
	FormatJSON                  = "JSON"
	FormatTEMPLATE              = "TEMPLATE"
)
View Source
const (
	MethodGet    CommandMethod = "GET"
	MethodPost                 = "POST"
	MethodPut                  = "PUT"
	MethodDelete               = "DELETE"
	MethodHead                 = "HEAD"
	MethodPatch                = "PATCH"
)
View Source
const FormatOptionTemplatePrefix string = "TEMPLATE="

Variables

View Source
var (
	ErrInvalidTargets       error = errors.New("Must specify at least one target configurer that will return valid targets, such as a file or cli arguments.")
	ErrInvalidTimeoutFormat       = errors.New("Timeout must conform to time.Duration format.")
	ErrInvalidRateFormat          = errors.New("Rate must conform to time.Duration format.")
	ErrInvalidMethod              = errors.New(fmt.Sprintf("Method unknown. Valid methods are %v", ValidMethods))
	ErrInvalidFormat              = errors.New(fmt.Sprintf("Output format unknown. Valid formats are %v", ValidFormats))
)
View Source
var DefaultHttpStatuses = map[string]int{
	string(MethodGet):    200,
	string(MethodPost):   201,
	string(MethodPut):    200,
	string(MethodDelete): 200,
	string(MethodHead):   200,
	string(MethodPatch):  200,
}
View Source
var ValidFormats = []string{"csv", "csv-md", "csv-no-color", "tab", "tab-md", "tab-no-color", "json", "json-compact", "template={{...}}"}
View Source
var ValidMethods = []string{"GET", "PUT", "POST", "DELETE", "HEAD", "PATCH"}

Functions

func GetMarkdownOptionOrDefault

func GetMarkdownOptionOrDefault(val string, defaultBoolean bool) bool

func GetPrettyOptionOrDefault

func GetPrettyOptionOrDefault(val string, defaultBoolean bool) bool

func GetTimeDurationConfig

func GetTimeDurationConfig(c *cli.Context, key string) time.Duration

func RegisterTargetConfigurer

func RegisterTargetConfigurer(tc TargetConfigurer)

RegisterTargetConfigurer ...

func RegisterWriterConfigurer

func RegisterWriterConfigurer(wc WriterConfigurer)

RegisterWriterConfigurer ...

Types

type CommandMethod

type CommandMethod string

type Configuration

type Configuration struct {
	CommandName     string
	Rate            time.Duration
	FormatString    string
	Output          OutputFormat
	Pretty          bool
	AggregateOutput bool
	Quiet           bool
	NoHeader        bool
	Markdown        bool
	FailuresOnly    bool
	StateChangeOnly bool
	Workers         int
	Targets         []*Target
	// contains filtered or unexported fields
}

func GetConfiguration

func GetConfiguration(c *cli.Context) (*Configuration, error)

func (*Configuration) ResultFormatter

func (config *Configuration) ResultFormatter() output.ResultFormatter

func (*Configuration) Writer

func (config *Configuration) Writer() io.Writer

func (*Configuration) WriterWithWriters

func (config *Configuration) WriterWithWriters(writers ...io.Writer) io.Writer

type Configurer

type Configurer interface {
	GetCommandFlags() []cli.Flag
}

Configurer ...

func GetAllConfigurers

func GetAllConfigurers() []Configurer

type OutputFormat

type OutputFormat string

func GetOutputFormatOrDefault

func GetOutputFormatOrDefault(val string, defaultFormat OutputFormat) OutputFormat

type Target

type Target struct {
	Label          string
	Method         CommandMethod
	Timeout        time.Duration
	ExpectedStatus int
	URL            string
	Headers        map[string]string
	Extra          map[string]interface{}
}

func NewTarget

func NewTarget(label string, urlString string, method CommandMethod, expectedStatus int) (*Target, error)

NewTarget creates a new config.Target object with the required fields.

func ParseTarget

func ParseTarget(targetString string) (*Target, error)

ParseTarget takes a string of format <url>|<method>|<status_code>|<label>|<header> and parses it into a config.Target object. URL is the only required field.

func (*Target) AddExtra

func (t *Target) AddExtra(key string, data interface{})

AddExtra is for writers of TargetConfigurers. This enables a way to attach data or track data from a target to its output.

type TargetConfigurer

type TargetConfigurer interface {
	Configurer
	GetTargets(c *cli.Context) ([]*Target, error)
}

TargetConfigurer ...

func GetTargetConfigurers

func GetTargetConfigurers() []TargetConfigurer

type WriterConfigurer

type WriterConfigurer interface {
	Configurer
	GetWriter(c *cli.Context) io.Writer
}

WriterConfigurer ...

func GetWriterConfigurers

func GetWriterConfigurers() []WriterConfigurer

Jump to

Keyboard shortcuts

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