Documentation ¶
Overview ¶
Package util provides utility functions used by other packages.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ArnRegexp *regexp.Regexp = regexp.MustCompile("arn:([^:]+):([^:]+):([^:]+):([^:]*):(.*)")
ArnRegexp matches an AWS ARN with the following capture groups:
1: partition 2: service 3: region 4: account-id 5: resource
Note that the resource may be in one of these forms:
resource, resourcetype:resource, resourcetype/resource
See: http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#genref-arns
var ErrGitDetached = errors.New("Your repo looks like it is in a detached state")
ErrDetached is returned if it looks like a Git repo is in a detached state.
Functions ¶
func CopyFile ¶
CopyFile copies the contents of one file to another file. If the dst file already exists, its contents will be replaced.
func NewCaptureLogger ¶
func NewCaptureLogger() (*CaptureWriter, *StandardLogger)
NewCaptureLogger returns a StandardLogger which will write its Print*() outputs to the returned CaptureWriter. This can be used to capture the outputs of Print*() methods instead of printing them to stdout.
Example ¶
w, log := NewCaptureLogger() log.Println("foo") // nothing written to stdout log.Debugln("bar") // "bar" is written to stderr log.Println("baz") // nothing written to stdout w.Out() // []string{"foo", "baz"}
Output:
Types ¶
type Arn ¶
An Arn specifies the pieces of an AWS ARN
type CaptureWriter ¶
type CaptureWriter struct {
// contains filtered or unexported fields
}
CaptureWriter is an io.Writer that simply captures its inputs in a []string.
Example ¶
w := &CaptureWriter{} w.Write([]byte("foo")) w.Write([]byte("bar")) w.Out() // []string{"foo", "bar"}
Output:
func (*CaptureWriter) Out ¶
func (w *CaptureWriter) Out() []string
type CmdOutput ¶
CmdOutput represents the output of a bash command.
type Logger ¶
type Logger interface { Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) Printf(format string, args ...interface{}) Warnf(format string, args ...interface{}) Warningf(format string, args ...interface{}) Errorf(format string, args ...interface{}) Fatalf(format string, args ...interface{}) Panicf(format string, args ...interface{}) Debug(args ...interface{}) Info(args ...interface{}) Print(args ...interface{}) Warn(args ...interface{}) Warning(args ...interface{}) Error(args ...interface{}) Fatal(args ...interface{}) Panic(args ...interface{}) Debugln(args ...interface{}) Infoln(args ...interface{}) Println(args ...interface{}) Warnln(args ...interface{}) Warningln(args ...interface{}) Errorln(args ...interface{}) Fatalln(args ...interface{}) Panicln(args ...interface{}) }
Logger is the interface used throughout devicefarm to write logs. The convention is that methods starting with Print write unformatted logs to sdout, while all other methods write formatted logs to stderr. Method signatures copied from Logrus: https://github.com/Sirupsen/logrus/blob/4b6ea7319e214d98c938f12692336f7ca9348d6b/logrus.go
type StandardLogger ¶
type StandardLogger struct { Logger // contains filtered or unexported fields }
StandardLogger is the basis for all loggers used in devicefarm.
var DefaultLogger *StandardLogger = NewStandardLogger(os.Stdout, os.Stderr)
DefaultLogger writes to stdout and stderr
var NilLogger *StandardLogger = NewStandardLogger(ioutil.Discard, ioutil.Discard)
NilLogger silences logs by writing to ioutil.Discard (equivalent of /dev/null)
func NewStandardLogger ¶
func NewStandardLogger(out, err io.Writer) *StandardLogger
NewStandardLogger creates a StandardLogger with the given io.Writers. For Print*() methods, the out io.Writer is used. For non-Print methods, a standard logrus.Logger is used (and it is provided the err io.Writer).
Example ¶
log := NewStandardLogger(os.Stdout, os.Stderr) log.Println("foo") // unformatted log to stdout log.Debugln("bar") // logrus formatted log to stderr
Output:
func (*StandardLogger) Print ¶
func (logger *StandardLogger) Print(args ...interface{})
func (*StandardLogger) Printf ¶
func (logger *StandardLogger) Printf(format string, args ...interface{})
func (*StandardLogger) Println ¶
func (logger *StandardLogger) Println(args ...interface{})