Documentation ¶
Index ¶
- Constants
- Variables
- func BuildArchive(ctx context.Context, tarWriter *tar.Writer, rootPath string, includes []string, ...) (int, error)
- func BuildFileList(startPath string, expressions ...string) ([]string, error)
- func CleanForPath(name string) string
- func CleanName(name string) string
- func DeepCopy(src, copy interface{}, registeredTypes []interface{}) error
- func ExpandValues(input interface{}, expansions *Expansions) error
- func Extract(ctx context.Context, tarReader *tar.Reader, rootPath string) error
- func FileExists(path 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 GetHTTPClient() *http.Client
- func GetIntValue(r *http.Request, valueKey string, defaultValue int) (int, error)
- func GetOAuth2HTTPClient(oauthToken string) (*http.Client, error)
- func GetRetryableOauth2HTTPClient(oauthToken string, fRetry rehttp.RetryFn, fDelay rehttp.DelayFn) (*http.Client, error)
- func GetStringArrayValue(r *http.Request, valueKey string, defaultValue []string) []string
- func IndexWhiteSpace(s string) int
- func IsExpandable(param string) bool
- func IsZeroTime(t time.Time) bool
- func JitterInterval(interval time.Duration) time.Duration
- 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 NewRequestReaderWithSize(req *http.Request, size int64) io.ReadCloser
- func PutHTTPClient(c *http.Client)
- func RandomString() string
- func ReadFromYAMLFile(fn string, data interface{}) error
- func ReadJSONInto(r io.ReadCloser, data interface{}) error
- func ReadYAMLInto(r io.ReadCloser, data interface{}) error
- func RehttpDelay(initialSleep time.Duration, numAttempts int) rehttp.DelayFn
- func Retry(op RetriableFunc, attempts int, sleep time.Duration) (bool, error)
- func RoundPartOfHour(num int) time.Time
- func RoundPartOfMinute(num int) time.Time
- func StringSliceContains(slice []string, item string) bool
- func StringSliceIntersection(a, b []string) []string
- func TarGzReader(path string) (f, gz io.ReadCloser, tarReader *tar.Reader, err error)
- func TarGzWriter(path string) (f, gz io.WriteCloser, tarWriter *tar.Writer, err error)
- 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 WriteCSVResponse(w http.ResponseWriter, status int, data interface{})
- func WriteJSON(w http.ResponseWriter, status int, data interface{})
- func WriteJSONInto(fn string, data interface{}) error
- func WriteTempFile(prefix string, data []byte) (string, error)
- func WriteToFile(body io.ReadCloser, filepath string) error
- func WriteToTempFile(data string) (string, error)
- type CappedWriter
- type Expansions
- func (self *Expansions) Exists(expansion string) bool
- func (self *Expansions) ExpandString(toExpand string) (string, error)
- func (self *Expansions) Get(expansion string) string
- func (self *Expansions) Put(expansion string, value string)
- func (self *Expansions) Update(newItems map[string]string)
- func (self *Expansions) UpdateFromYaml(filename string) error
- type KeyValuePair
- type KeyValuePairSlice
- type RetriableFunc
- type SafeCounter
- type StaticHostInfo
- type StringOrBool
- type TarContentsFile
Constants ¶
const (
DefaultSSHPort = "22"
)
Variables ¶
var ErrBufferFull = errors.New("buffer full")
ErrBufferFull indicates that a CappedWriter's bytes.Buffer has MaxBytes bytes.
var ZeroTime time.Time = time.Unix(0, 0)
ZeroTime represents 0 in epoch time
Functions ¶
func BuildArchive ¶
func BuildArchive(ctx context.Context, tarWriter *tar.Writer, rootPath string, includes []string, excludes []string, logger grip.Journaler) (int, error)
BuildArchive reads the rootPath directory into the tar.Writer, taking included and excluded strings into account. Returns the number of files that were added to the archive
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 DeepCopy ¶
func DeepCopy(src, copy interface{}, registeredTypes []interface{}) error
DeepCopy makes a deep copy of the src value into the copy params The registeredTypes param can be optionally used to register additional types that need to be used by gob
func ExpandValues ¶
func ExpandValues(input interface{}, expansions *Expansions) error
Taking in the input and expansions map, apply the expansions to any appropriate fields in the input. The input must be a pointer to a struct so that the underlying struct can be modified.
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 GetHTTPClient ¶
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 IsExpandable ¶
IsExpandable returns true if the passed in string contains an expandable parameter
func IsZeroTime ¶
IsZeroTime checks that a time is either equal to golang ZeroTime or UTC ZeroTime.
func JitterInterval ¶
JitterInterval returns a duration that some value between the interval and 2x the interval.
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 NewRequestReaderWithSize ¶
func NewRequestReaderWithSize(req *http.Request, size int64) io.ReadCloser
NewRequestReaderWithSize returns an io.ReadCloser closer for the body of an *http.Request with a user-specified size.
func PutHTTPClient ¶
func RandomString ¶
func RandomString() string
RandomString returns a cryptographically random string.
func ReadFromYAMLFile ¶
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 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 RoundPartOfHour ¶
ParseRoundPartOfHour produces a time value with the minute value rounded down to the most recent interval.
func RoundPartOfMinute ¶
ParseRoundPartOfMinute produces a time value with the second value rounded down to the most recent interval.
func StringSliceContains ¶
StringSliceContains determines if a string is in a slice
func StringSliceIntersection ¶
StringSliceIntersection returns the intersecting elements of slices a and b.
func TarGzReader ¶
TarGzReader returns a file, gzip reader, and tar reader for the given path. The tar reader wraps the gzip reader, which wraps the file.
func TarGzWriter ¶
TarGzWriter returns a file, gzip writer, and tarWriter for the path. The tar writer wraps the gzip writer, which wraps the file.
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 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, status int, data interface{})
WriteJSON writes a json response with the supplied code on the given writer.
func WriteJSONInto ¶
func WriteTempFile ¶
WriteTempFile creates a temp file, writes the data to it, closes it and returns the file name.
func WriteToFile ¶
func WriteToFile(body io.ReadCloser, filepath string) error
WriteToFile takes in a body and filepath and writes out the data in the body
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 Expansions ¶
Wrapper for an expansions map, with some utility functions.
func NewExpansions ¶
func NewExpansions(initMap map[string]string) *Expansions
Return a new Expansions object with all of the specified expansions present.
func (*Expansions) Exists ¶
func (self *Expansions) Exists(expansion string) bool
Check if a value is present in the expansions.
func (*Expansions) ExpandString ¶
func (self *Expansions) ExpandString(toExpand string) (string, error)
Apply the expansions to a single string. Return the expanded string, or an error if the input string is malformed.
func (*Expansions) Get ¶
func (self *Expansions) Get(expansion string) string
Get a single value from the expansions. Return the value, or the empty string if the value is not present.
func (*Expansions) Put ¶
func (self *Expansions) Put(expansion string, value string)
Set a single value in the expansions.
func (*Expansions) Update ¶
func (self *Expansions) Update(newItems map[string]string)
Update all of the specified keys in the expansions to point to the specified values.
func (*Expansions) UpdateFromYaml ¶
func (self *Expansions) UpdateFromYaml(filename string) error
Read a map of keys/values from the given file, and update the expansions to include them (overwriting any duplicates with the new value).
type KeyValuePair ¶
type KeyValuePair struct { Key string `bson:"key" json:"key" yaml:"key"` Value interface{} `bson:"value" json:"value" yaml:"value"` }
func MakeKeyValuePair ¶
func MakeKeyValuePair(in map[string]string) []KeyValuePair
func MakeNestedKeyValuePair ¶
func MakeNestedKeyValuePair(in map[string]map[string]string) []KeyValuePair
type KeyValuePairSlice ¶
type KeyValuePairSlice []KeyValuePair
type RetriableFunc ¶
RetriableFunc is any function that takes no parameters and returns only an error interface. These functions can be used with util.Retry.
type SafeCounter ¶
type SafeCounter struct {
// contains filtered or unexported fields
}
func (*SafeCounter) Inc ¶
func (s *SafeCounter) Inc()
func (*SafeCounter) String ¶
func (s *SafeCounter) String() string
func (*SafeCounter) Value ¶
func (s *SafeCounter) Value() int
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}
type StringOrBool ¶
type StringOrBool string
func (*StringOrBool) Bool ¶
func (v *StringOrBool) Bool() (bool, error)
func (*StringOrBool) MarshalJSON ¶
func (v *StringOrBool) MarshalJSON() ([]byte, error)
func (*StringOrBool) MarshalYAML ¶
func (v *StringOrBool) MarshalYAML() (interface{}, error)
func (*StringOrBool) UnmarshalJSON ¶
func (v *StringOrBool) UnmarshalJSON(in []byte) error
func (*StringOrBool) UnmarshalYAML ¶
func (v *StringOrBool) UnmarshalYAML(um func(interface{}) error) error
type TarContentsFile ¶
type TarContentsFile struct {
// contains filtered or unexported fields
}
TarContentsFile represents a tar file on disk.