utils

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package utils simply defines utility functions and types.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCouldNotExtract occurs when an extraction fails.
	ErrCouldNotExtract = errors.New("utils: could not extract the archive")

	// ErrExtractedFileTooBig occurs when a file to extract is too big.
	ErrExtractedFileTooBig = errors.New("utils: could not extract one or more files from the archive: file too big")
)

Functions

func CleanURL

func CleanURL(str string) string

CleanURL removes all parameters from an URL.

func CompareStringLists

func CompareStringLists(X, Y []string) []string

CompareStringLists returns the strings that are present in X but not in Y.

func CompareStringListsInBoth added in v1.0.0

func CompareStringListsInBoth(X, Y []string) []string

CompareStringListsInBoth returns the strings that are present in both X and Y.

func Contains

func Contains(needle string, haystack []string) bool

Contains looks for a string into an array of strings and returns whether the string exists.

func Exec

func Exec(dir string, bin string, args ...string) ([]byte, error)

Exec runs the given binary with arguments

func PrometheusObserveTimeMilliseconds added in v1.0.0

func PrometheusObserveTimeMilliseconds(h prometheus.Histogram, start time.Time)

PrometheusObserveTimeMilliseconds observes the elapsed time since start, in milliseconds, on the specified Prometheus Histogram.

func SelectivelyExtractArchive

func SelectivelyExtractArchive(r io.Reader, prefix string, toExtract []string, maxFileSize int64) (map[string][]byte, error)

SelectivelyExtractArchive extracts the specified files and folders from targz data read from the given reader and store them in a map indexed by file paths

Types

type Stopper

type Stopper struct {
	// contains filtered or unexported fields
}

Stopper eases the graceful termination of a group of goroutines

func NewStopper

func NewStopper() *Stopper

NewStopper initializes a new Stopper instance

func (*Stopper) Begin

func (s *Stopper) Begin()

Begin indicates that a new goroutine has started.

func (*Stopper) Chan

func (s *Stopper) Chan() chan struct{}

Chan returns the channel on which goroutines could listen to determine if they should stop. The channel is closed when Stop() is called.

func (*Stopper) End

func (s *Stopper) End()

End indicates that a goroutine has stopped.

func (*Stopper) Sleep

func (s *Stopper) Sleep(d time.Duration) bool

Sleep puts the current goroutine on sleep during a duration d Sleep could be interrupted in the case the goroutine should stop itself, in which case Sleep returns false.

func (*Stopper) Stop

func (s *Stopper) Stop()

Stop asks every goroutine to end.

type TarReadCloser added in v1.0.0

type TarReadCloser struct {
	*tar.Reader
	io.Closer
}

TarReadCloser embeds a *tar.Reader and the related io.Closer It is the caller's responsibility to call Close on TarReadCloser when done.

func (*TarReadCloser) Close added in v1.0.0

func (r *TarReadCloser) Close() error

type XzReader added in v1.0.0

type XzReader struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

XzReader is an io.ReadCloser which decompresses xz compressed data.

func NewXzReader added in v1.0.0

func NewXzReader(r io.Reader) (*XzReader, error)

NewXzReader shells out to a command line xz executable (if available) to decompress the given io.Reader using the xz compression format and returns an *XzReader. It is the caller's responsibility to call Close on the XzReader when done.

func (*XzReader) Close added in v1.0.0

func (r *XzReader) Close() error

Directories

Path Synopsis
Package errors defines error types that are used in several modules
Package errors defines error types that are used in several modules
Package http provides utility functions for HTTP servers and clients.
Package http provides utility functions for HTTP servers and clients.
Package types defines useful types that are used in database models.
Package types defines useful types that are used in database models.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL