common

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package common contains general-purpose types and helpers. Ideally, it should remain as small as possible.

Index

Constants

View Source
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

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies a file from src to dst. If src and dst files exist, and are the same, then return successfully. Otherise, attempt to copy the file contents from src to dst. The file will be created if it does not already exist. If the destination file exists, all it's contents will be replaced by the contents of the source file.

func FileExists

func FileExists(path string) bool

FileExists asserts whether a file path exists.

Types

type Base

type Base struct {
	CmdClause *kingpin.CmdClause
	Globals   *config.Data
}

Base is stuff that should be included in every concrete command.

func (Base) Name

func (b Base) Name() string

Name implements the Command interface, and returns the FullCommand from the kingpin.Command that's used to select which command to actually run.

type Command

type Command interface {
	Name() string
	Exec(in io.Reader, out io.Writer) error
}

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.

func SelectCommand

func SelectCommand(name string, commands []Command) (Command, bool)

SelectCommand chooses the command matching name, if it exists.

type Globals

type Globals struct {
	Token   string
	Verbose bool
	Client  api.Interface
}

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 {
	Valid 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

Set implements kingpin.Action and is used as callback to set that the optional inner value is valid.

type OptionalBool

type OptionalBool struct {
	Optional
	Value bool
}

OptionalBool models an optional boolean flag value.

type OptionalString

type OptionalString struct {
	Optional
	Value string
}

OptionalString models an optional string flag value.

type OptionalStringSlice

type OptionalStringSlice struct {
	Optional
	Value []string
}

OptionalStringSlice models an optional string slice flag value.

type OptionalUint

type OptionalUint struct {
	Optional
	Value uint
}

OptionalUint models an optional unit flag value.

type Registerer

type Registerer interface {
	Command(name, help string) *kingpin.CmdClause
}

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 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.

func (*SyncWriter) Write

func (w *SyncWriter) Write(p []byte) (int, error)

Write implements io.Writer with mutex protection.

Jump to

Keyboard shortcuts

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