Documentation ¶
Index ¶
- Variables
- func AbsPath(inPath string) string
- func CheckPreconditions(w http.ResponseWriter, r *http.Request, etag string) (done bool)
- func CleanUTF8(s string) string
- func CloneURL(u *url.URL) *url.URL
- func CookieDomain(domain string) string
- func DirExists(name string) (bool, error)
- func DurationFuzzing(d time.Duration, variation float64) time.Duration
- func FileExists(name string) (bool, error)
- func IsInArray(s string, a []string) bool
- func LimitWriter(w io.Writer, n int64) io.Writer
- func LimitWriterDiscard(w io.Writer, n int64) io.Writer
- func NewSeededRand(seed int64) io.Reader
- func RandomString(n int) string
- func RandomStringFast(rng *rand.Rand, n int) string
- func ReadCloser(r io.Reader, c func() error) io.ReadCloser
- func RetryWithExpBackoff(count int, delay time.Duration, fn func() error) error
- func SplitTrimString(s, sep string) []string
- func StripPort(domain string) string
- func TrimStrings(strs []string) []string
- func UniqueStrings(strs []string) []string
- func WriteCloser(w io.Writer, c func() error) io.WriteCloser
- type GroupShutdown
- type Shutdowner
Constants ¶
This section is empty.
Variables ¶
var NopShutdown = NewGroupShutdown()
NopShutdown implements the Shutdowner interface but does not execute any process on shutdown.
Functions ¶
func CheckPreconditions ¶
CheckPreconditions evaluates request preconditions based only on the Etag values.
func CookieDomain ¶
CookieDomain removes the port and does IDNA encoding.
func DurationFuzzing ¶
DurationFuzzing returns a duration that is near the given duration, but randomized to avoid patterns like several cache entries that expires at the same time.
func FileExists ¶
FileExists returns whether or not the file exists on the current file system.
func LimitWriter ¶
LimitWriter works like io.LimitReader. It writes at most n bytes to the underlying Writer. It returns io.ErrShortWrite if more than n bytes are attempted to be written.
func LimitWriterDiscard ¶
LimitWriterDiscard works like io.LimitReader. It writes at most n bytes to the underlying Writer. It does not return any error if more than n bytes are attempted to be written, the data is discarded.
func NewSeededRand ¶
NewSeededRand returns a random bytes reader initialized with the given seed.
func RandomString ¶
RandomString returns a string of random alpha characters of the specified length.
func RandomStringFast ¶
RandomStringFast returns a random string containing printable ascii characters: [0-9a-zA-Z_-]{n}. Each character encodes 6bits of entropy. To avoid wasting entropy, it is better to create a string whose length is a multiple of 10. For instance a 20 bytes string will encode 120 bits of entropy.
func ReadCloser ¶
func ReadCloser(r io.Reader, c func() error) io.ReadCloser
ReadCloser returns an io.ReadCloser from a io.Reader and a close method.
func RetryWithExpBackoff ¶
RetryWithExpBackoff can be used to call several times a function until it returns no error or the maximum count of calls has been reached. Between two calls, it will wait, first by the given delay, and after that, the delay will double after each failure.
func SplitTrimString ¶
SplitTrimString slices s into all substrings a s separated by sep, like strings.Split. In addition it will trim all those substrings and filter out the empty ones.
func TrimStrings ¶
TrimStrings trim all strings and filter out the empty ones.
func UniqueStrings ¶
UniqueStrings returns a filtered slice without string duplicates.
func WriteCloser ¶
func WriteCloser(w io.Writer, c func() error) io.WriteCloser
WriteCloser returns an io.WriteCloser from a io.Writer and a close method.
Types ¶
type GroupShutdown ¶
type GroupShutdown struct {
// contains filtered or unexported fields
}
GroupShutdown allow to group multiple Shutdowner into a single one.
func NewGroupShutdown ¶
func NewGroupShutdown(s ...Shutdowner) *GroupShutdown
NewGroupShutdown returns a new GroupShutdown
func (*GroupShutdown) Shutdown ¶
func (g *GroupShutdown) Shutdown(ctx context.Context) error
Shutdown closes all the encapsulated Shutdowner in parallel an returns the concatenated errors.
type Shutdowner ¶
Shutdowner is an interface with a Shutdown method to gracefully shutdown a running process.