Documentation ¶
Index ¶
- Constants
- Variables
- func BuildFileList(startPath string, expressions ...string) ([]string, error)
- func CleanForPath(name string) string
- func CleanName(name string) string
- func FileExists(elem ...string) (bool, error)
- func FromNanoseconds(duration time.Duration) int64
- func FromPythonTime(pyTime float64) time.Time
- func GetBoolValue(r *http.Request, valueKey string, defaultValue bool) (bool, error)
- func GetIntValue(r *http.Request, valueKey string, defaultValue int) (int, error)
- func GetStringArrayValue(r *http.Request, valueKey string, defaultValue []string) []string
- func IndexWhiteSpace(s string) int
- func IsZeroTime(t time.Time) bool
- func MakeTlsConfig(cert string, key string) (*tls.Config, error)
- func Min(a ...int) int
- func MountHandler(r *mux.Router, prefix string, h http.Handler) http.Handler
- func NewRequestReader(req *http.Request) io.ReadCloser
- func RandomString() string
- func ReadJSONInto(r io.ReadCloser, data interface{}) error
- func ReadYAMLInto(r io.ReadCloser, data interface{}) error
- func RecoverAndLogStackTrace()
- func Retry(op RetriableFunc, attempts int, sleep time.Duration) (bool, error)
- func RunFunctionWithTimeout(f func() error, timeout time.Duration) error
- func SliceContains(slice, elt interface{}) bool
- func StringSliceIntersection(a, b []string) []string
- func ToNanoseconds(duration time.Duration) time.Duration
- func ToPythonTime(t time.Time) float64
- func Truncate(input string, outputLength int) string
- func UniqueStrings(slice []string) []string
- func UnmarshalYAMLFile(file string, data interface{}) error
- func WriteCSVResponse(w http.ResponseWriter, status int, data interface{})
- func WriteJSON(w *http.ResponseWriter, data interface{}, status int)
- func WriteTempFile(prefix string, data []byte) (string, error)
- func WriteToTempFile(data string) (string, error)
- type CappedWriter
- type LineBufferingWriter
- type RetriableError
- type RetriableFunc
- type SizeTrackingReader
- type StaticHostInfo
Constants ¶
const (
DefaultSSHPort = "22"
)
Variables ¶
var ErrBufferFull = errors.New("buffer full")
ErrBufferFull indicates that a CappedWriter's bytes.Buffer has MaxBytes bytes.
var ( // ErrTimedOut is returned by a function that timed out. ErrTimedOut = errors.New("Function timed out") )
var ZeroTime time.Time = time.Unix(0, 0)
ZeroTime represents 0 in epoch time
Functions ¶
func BuildFileList ¶
BuildFileList returns a list of files that match the given list of expressions rooted at the given startPath. The expressions correspond to gitignore ignore expressions: anything that would be matched - and therefore ignored by git - is included in the returned list of file paths. BuildFileList does not follow symlinks as it uses filpath.Walk, which does not follow symlinks.
func CleanForPath ¶
func FileExists ¶
FileExists returns true if 'path' exists.
func FromNanoseconds ¶
fromNanoSeconds returns milliseconds of a duration for queries in the database.
func FromPythonTime ¶
FromPythonTime returns a time.Time that corresponds to the float style python time which is <seconds>.<fractional_seconds> from unix epoch.
func GetBoolValue ¶
GetBoolValue returns a form value as an integer
func GetIntValue ¶
GetIntValue returns a form value as an integer
func GetStringArrayValue ¶
GetStringArrayValue returns a form value as a string array
func IndexWhiteSpace ¶
IndexWhiteSpace returns the first index of white space in the given string. Returns -1 if no white space exists.
func IsZeroTime ¶
IsZeroTime checks that a time is either equal to golang ZeroTime or UTC ZeroTime.
func MakeTlsConfig ¶
MakeTlsConfig creates a TLS Config from a certificate and key.
func MountHandler ¶
MountHandler routes all requests to the given mux.Router under the prefix to be handled by the http.Handler, which the request's path rooted under that prefix. So for example, if a router configured with the path /foo is given to MountHandler(r, "/bar/baz", newHandler) Then a request to the router at /foo/bar/baz/hello will be handled by newHandler, appearing with the path "/baz/hello"
func NewRequestReader ¶
func NewRequestReader(req *http.Request) io.ReadCloser
NewRequestReader returns an io.ReadCloser closer for the body of an *http.Request, using a limited reader internally to avoid unbounded reading from the request body. The reader is limited to 16 megabytes.
func RandomString ¶
func RandomString() string
RandomString returns a cryptographically random string.
func ReadJSONInto ¶
func ReadJSONInto(r io.ReadCloser, data interface{}) error
ReadJSONInto reads JSON from an io.ReadCloser into the data pointer.
func ReadYAMLInto ¶
func ReadYAMLInto(r io.ReadCloser, data interface{}) error
ReadYAMLInto reads data for the given io.ReadCloser - until it hits an error or reaches EOF - and attempts to unmarshal the data read into the given interface.
func RecoverAndLogStackTrace ¶
func RecoverAndLogStackTrace()
RecoverAndLogStackTrace captures a panic stack trace and writes it to the log file rather than allowing it to be printed to standard error, where it would be lost (in the case of agents.)
func Retry ¶
Retry provides a mechanism to retry an operation with exponential backoff (that uses some jitter,) Specify the maximum number of retry attempts that you want to permit as well as the initial period that you want to sleep between attempts.
Retry requires that the starting sleep interval be at least 100 milliseconds, and forces this interval if you attempt to use a shorter period.
If you specify 0 attempts, Retry will use an attempt value of one.
func RunFunctionWithTimeout ¶
RunFunctionWithTimeout runs a function, timing out after the specified time. The error returned will be the return value of the function if it completes, or ErrTimedOut if it times out.
func SliceContains ¶
func SliceContains(slice, elt interface{}) bool
SliceContains returns true if elt is in slice, panics if slice is not of Kind reflect.Slice
func StringSliceIntersection ¶
StringSliceIntersection returns the intersecting elements of slices a and b.
func ToNanoseconds ¶
fromNanoSeconds returns milliseconds of a duration for queries in the database.
func ToPythonTime ¶
ToPythonTime returns a number in the format that python's time.time() returns as a float with <seconds>.<fractional_seconds>
func UniqueStrings ¶
UniqueStrings takes a slice of strings and returns a new slice with duplicates removed. Order is preserved.
func UnmarshalYAMLFile ¶
UnmarshalYAMLFile reads in the specified file, and unmarshals it into the given interface. Returns an error if one is encountered in reading the file or if the file does not contain valid YAML.
func WriteCSVResponse ¶
func WriteCSVResponse(w http.ResponseWriter, status int, data interface{})
WriteToCSVResponse takes in an interface that is a slice or an array and converts the struct to csv for fields that have the the csv struct tag.
func WriteJSON ¶
func WriteJSON(w *http.ResponseWriter, data interface{}, status int)
WriteJSON writes a json response with the supplied code on the given writer.
func WriteTempFile ¶
WriteTempFile creates a temp file, writes the data to it, closes it and returns the file name.
func WriteToTempFile ¶
WriteToTempFile writes the given string to a temporary file and returns the path to the file.
Types ¶
type CappedWriter ¶
CappedWriter implements a buffer that stores up to MaxBytes bytes. Returns ErrBufferFull on overflowing writes
func (*CappedWriter) IsFull ¶
func (cw *CappedWriter) IsFull() bool
IsFull indicates whether the buffer is full.
func (*CappedWriter) String ¶
func (cw *CappedWriter) String() string
String return the contents of the buffer as a string.
type LineBufferingWriter ¶
type LineBufferingWriter struct {
// contains filtered or unexported fields
}
LineBufferingWriter is an implementation of io.Writer that sends the newline delimited subslices of its inputs to a wrapped io.Writer, buffering as needed.
func NewLineBufferingWriter ¶
func NewLineBufferingWriter(wrapped io.Writer) *LineBufferingWriter
func (*LineBufferingWriter) Flush ¶
func (lbw *LineBufferingWriter) Flush() error
writes whatever is in the buffer out using the wrapped io.Writer
type RetriableError ¶
type RetriableError struct {
Failure error
}
RetriableError can be returned by any function called with Retry(), to indicate that it should be retried again after a sleep interval.
func (RetriableError) Error ¶
func (e RetriableError) Error() string
type RetriableFunc ¶
type RetriableFunc func() error
RetriableFunc is any function that takes no parameters and returns only an error interface. These functions can be used with util.Retry.
type SizeTrackingReader ¶
type StaticHostInfo ¶
StaticHostInfo stores the connection parameters for connecting to an SSH host.
func ParseSSHInfo ¶
func ParseSSHInfo(fullHostname string) (*StaticHostInfo, error)
ParseSSHInfo reads in a hostname definition and reads the relevant SSH connection information from it. For example,
"admin@myhostaddress:24"
will return
StaticHostInfo{User: "admin", Hostname:"myhostaddress", Port: 24}