Documentation
¶
Overview ¶
Package common contains general-purpose types and helpers. Ideally, it should remain as small as possible.
Index ¶
Constants ¶
const TimeFormat = "2006-01-02 15:04"
TimeFormat is a format string for time.Format that reflects what the Fastly web UI uses.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
Command is an interface that abstracts over all of the concrete command structs. The Name method lets us select which command should be run, and the Exec method invokes whatever business logic the command should do.
type Globals ¶
Globals are flags and other stuff that's useful to every command. Globals are passed to each concrete command's constructor as a pointer, and are populated after a call to Parse. A concrete command's Exec method can use any of the information in the globals.
type Optional ¶
type Optional struct {
WasSet bool
}
Optional models an optional type that consumers can use to assert whether the inner value has been set and is therefore valid for use.
func (*Optional) Set ¶
func (o *Optional) Set(e *kingpin.ParseElement, c *kingpin.ParseContext) error
Set implements kingpin.Action and is used as callback to set that the optional inner value is valid.
type OptionalBool ¶
OptionalBool models an optional boolean flag value.
type OptionalInt ¶ added in v0.9.0
OptionalInt models an optional int flag value.
type OptionalString ¶
OptionalString models an optional string flag value.
type OptionalStringSlice ¶
OptionalStringSlice models an optional string slice flag value.
type OptionalUint ¶
OptionalUint models an optional uint flag value.
type OptionalUint8 ¶ added in v0.9.0
OptionalUint8 models an optional unit8 flag value.
type Registerer ¶
Registerer abstracts over a kingpin.App and kingpin.CmdClause. We pass it to each concrete command struct's constructor as the "parent" into which the command should install itself.
type StreamingExec ¶ added in v0.18.0
type StreamingExec struct {
// contains filtered or unexported fields
}
StreamingExec models a generic command execution that consumers can use to execute commands and stream their output to an io.Writer. For example compute commands can use this to standardize the flow control for each compiler toolchain.
func NewStreamingExec ¶ added in v0.18.0
NewStreamingExec constructs a new StreamingExec instance.
func (StreamingExec) Exec ¶ added in v0.18.0
func (s StreamingExec) Exec() error
Exec executes the compiler command and pipes the child process stdout and stderr output to the supplied io.Writer, it waits for the command to exit cleanly or returns an error.
type SyncWriter ¶
type SyncWriter struct {
// contains filtered or unexported fields
}
SyncWriter protects any io.Writer with a mutex.
func NewSyncWriter ¶
func NewSyncWriter(w io.Writer) *SyncWriter
NewSyncWriter wraps an io.Writer with a mutex.
type UndoFn ¶ added in v0.3.0
type UndoFn func() error
UndoFn is a function with no arguments which returns an error or nil.
type UndoStack ¶ added in v0.3.0
type UndoStack struct {
// contains filtered or unexported fields
}
UndoStack models a simple undo stack which consumers can use to store undo stateful functions, such as a function to teardown API state if something goes wrong during procedural commands, for example deleting a Fastly service after it's been created.
func NewUndoStack ¶ added in v0.3.0
func NewUndoStack() *UndoStack
NewUndoStack constructs a new UndoStack.
func (*UndoStack) Pop ¶ added in v0.3.0
Pop method pops last added UndoFn element oof the stack and returns it. If stack is empty Pop() returns nil.
func (*UndoStack) RunIfError ¶ added in v0.3.0
RunIfError unwinds the stack if a non-nil error is passed, by serially calling each UndoFn function state in FIFO order. If any UndoFn returns an error, it gets logged to the provided writer. Should be deferrerd, such as:
undoStack := common.NewUndoStack() defer func() { undoStack.RunIfError(w, err) }()