Documentation ¶
Index ¶
- Constants
- Variables
- func CleanName(name string) string
- func CurrentGitHash(repoDir string) (string, error)
- func DumpStackOnSIGQUIT(stackOut io.Writer)
- func FileExists(elem ...string) (bool, error)
- func GetAppendingFile(path string) (*os.File, error)
- 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 RandomString() string
- func ReadJSONInto(r io.ReadCloser, data interface{}) error
- func ReadYAMLInto(r io.ReadCloser, data interface{}) error
- func RemoveSuffix(s, suffix string) string
- func Retry(attemptFunc RetriableFunc, maxTries int, sleep time.Duration) (bool, error)
- func RetryArithmeticBackoff(attemptFunc RetriableFunc, maxTries int, sleep time.Duration) (bool, error)
- func RetryGeometricBackoff(attemptFunc RetriableFunc, maxTries int, sleep time.Duration) (bool, error)
- func RunFunctionWithTimeout(f func() error, timeout time.Duration) error
- func SliceContains(slice, elt interface{}) bool
- func Truncate(input string, outputLength int) string
- func UnmarshalYAMLFile(file string, data interface{}) error
- func WriteJSON(w *http.ResponseWriter, data interface{}, status int)
- func WriteToTempFile(data string) (string, error)
- type BackoffCalc
- type LineBufferingWriter
- type RetriableError
- type RetriableFunc
- type StaticHostInfo
Constants ¶
const (
DefaultSSHPort = "22"
)
Variables ¶
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 CurrentGitHash ¶
CurrentGitHash returns the current git hash of the git repository located at the specified directory.
func DumpStackOnSIGQUIT ¶
DumpStackOnSIGQUIT listens for a SIGQUIT signal and writes stack dump to the given io.Writer when one is received. Blocks, so spawn it as a goroutine.
func FileExists ¶
FileExists returns true if 'path' exists.
func GetAppendingFile ¶
GetAppendingFile opens a file for appending. The file will be created if it does not already exist.
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 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 RemoveSuffix ¶
RemoveSuffix returns s with 'suffix' removed from end of string if present
func Retry ¶
Retry will call attemptFunc up to maxTries until it returns nil, sleeping the specified amount of time between each call. The function can return an error to abort the retrying, or return RetriableError to allow the function to be called again.
func RetryArithmeticBackoff ¶
func RetryArithmeticBackoff(attemptFunc RetriableFunc, maxTries int, sleep time.Duration) (bool, error)
RetryArithmeticBackoff will call attemptFunc up to maxTries until it returns nil, leeping for an arithmetic progressed duration after each retry attempt. e.g. For if attemptFunc errors out immediately, the sleep duration for a call like RetryArithmeticBackoff(func, 3, 5) would be thus:
1st iteration: Sleep duration 5 seconds 2nd iteration: Sleep duration 10 seconds 3rd iteration: Sleep duration 15 seconds ... The function can return an error to abort the retrying, or return RetriableError to allow the function to be called again.
func RetryGeometricBackoff ¶
func RetryGeometricBackoff(attemptFunc RetriableFunc, maxTries int, sleep time.Duration) (bool, error)
RetryGeometricBackoff will call attemptFunc up to maxTries until it returns nil, leeping for an geometric progressed duration after each retry attempt. e.g. For if attemptFunc errors out immediately, the sleep duration for a call like RetryGeometricBackoff(func, 3, 5) would be thus:
1st iteration: Sleep duration 5 seconds 2nd iteration: Sleep duration 25 seconds 3rd iteration: Sleep duration 125 seconds ... The function can return an error to abort the retrying, or return RetriableError to allow the function to be called again.
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 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 WriteJSON ¶
func WriteJSON(w *http.ResponseWriter, data interface{}, status int)
WriteJSON writes a json response with the supplied code on the given writer.
func WriteToTempFile ¶
WriteToTempFile writes the given string to a temporary file and returns the path to the file.
Types ¶
type BackoffCalc ¶
BackoffCalc is a custom function signature that can be implemented by any implementation that returns a sleep duration for backoffs
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 (retriable 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 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}