utils

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2014 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StdWriterPrefixLen = 8
	StdWriterFdIndex   = 0
	StdWriterSizeIndex = 4
)

Variables

View Source
var ErrInvalidStdHeader = errors.New("Unrecognized input header")

Functions

func CheckLocalDns added in v0.4.1

func CheckLocalDns(resolvConf []byte) bool

CheckLocalDns looks into the /etc/resolv.conf, it returns true if there is a local nameserver or if there is no nameserver.

func CompareKernelVersion

func CompareKernelVersion(a, b *KernelVersionInfo) int

Compare two KernelVersionInfo struct. Returns -1 if a < b, 0 if a == b, 1 it a > b

func CopyDirectory added in v0.3.4

func CopyDirectory(source, dest string) error

FIXME: this is deprecated by CopyWithTar in archive.go

func CopyEscapable

func CopyEscapable(dst io.Writer, src io.ReadCloser) (written int64, err error)

Code c/c from io.Copy() modified to handle escape sequence

func CopyFile added in v0.7.0

func CopyFile(src, dst string) (int64, error)

func CreatePidFile added in v0.6.6

func CreatePidFile(pidfile string) error

func Debugf

func Debugf(format string, a ...interface{})

Debug function, if the debug flag is set, then display. Do nothing otherwise If Docker is in damon mode, also send the debug info on the socket

func DisplayJSONMessagesStream added in v0.6.0

func DisplayJSONMessagesStream(in io.Reader, out io.Writer, terminalFd uintptr, isTerminal bool) error

func DockerInitPath added in v0.6.5

func DockerInitPath(localCopy string) string

Figure out the path of our dockerinit (which may be SelfPath())

func Download

func Download(url string) (resp *http.Response, err error)

Request a given URL and return an io.Reader

func Errorf added in v0.6.4

func Errorf(format string, a ...interface{})

func GenerateRandomID added in v0.10.0

func GenerateRandomID() string

GenerateRandomID returns an unique id

func GetCallerName added in v0.6.7

func GetCallerName(depth int) string

GetCallerName introspects the call stack and returns the name of the function `depth` levels down in the stack.

func GetLines added in v0.10.0

func GetLines(input []byte, commentMarker []byte) [][]byte

GetLines parses input into lines and strips away comments.

func GetTotalUsedFds

func GetTotalUsedFds() int

func Go

func Go(f func() error) chan error

Go is a basic promise implementation: it wraps calls a function in a goroutine, and returns a channel which will later return the function's return value.

func HashData

func HashData(src io.Reader) (string, error)

func IsGIT added in v0.4.5

func IsGIT(str string) bool

func IsURL added in v0.4.5

func IsURL(str string) bool

func NewBufReader

func NewBufReader(r io.Reader) *bufReader

func NewHTTPRequestError added in v0.6.0

func NewHTTPRequestError(msg string, res *http.Response) error

func NewReadCloserWrapper added in v0.8.0

func NewReadCloserWrapper(r io.Reader, closer func() error) io.ReadCloser

func NewTimeoutConn added in v0.12.0

func NewTimeoutConn(conn net.Conn, timeout time.Duration) net.Conn

func NopWriteCloser

func NopWriteCloser(w io.Writer) io.WriteCloser

func ParseHost added in v0.4.3

func ParseHost(defaultHost string, defaultUnix, addr string) (string, error)

FIXME: Change this not to receive default value as parameter

func ParseKeyValueOpt added in v0.10.0

func ParseKeyValueOpt(opt string) (string, string, error)

func ParseRepositoryTag added in v0.5.0

func ParseRepositoryTag(repos string) (string, string)

Get a repos name and returns the right reposName + tag The tag can be confusing because of a port in a repository name.

Ex: localhost.localdomain:5000/samalba/hipache:latest

func PartParser added in v0.6.5

func PartParser(template, data string) (map[string]string, error)

func ProgressReader

func ProgressReader(r io.ReadCloser, size int, output io.Writer, sf *StreamFormatter, newline bool, ID, action string) *progressReader

func RandomString added in v0.6.6

func RandomString() string

func ReadSymlinkedDirectory added in v0.9.0

func ReadSymlinkedDirectory(path string) (string, error)

ReadSymlinkedDirectory returns the target directory of a symlink. The target of the symbolic link may not be a file.

func RemovePidFile added in v0.6.6

func RemovePidFile(pidfile string)

func ReplaceOrAppendEnvValues added in v0.9.0

func ReplaceOrAppendEnvValues(defaults, overrides []string) []string

ReplaceOrAppendValues returns the defaults with the overrides either replaced by env key or appended to the list

func ResumableRequestReader added in v0.12.0

func ResumableRequestReader(c *http.Client, r *http.Request, maxfail uint32, totalsize int64) io.ReadCloser

ResumableRequestReader makes it possible to resume reading a request's body transparently maxfail is the number of times we retry to make requests again (not resumes) totalsize is the total length of the body; auto detect if not provided

func SelfPath

func SelfPath() string

Figure out the absolute path of our own binary (if it's still around).

func ShellQuoteArguments added in v0.6.7

func ShellQuoteArguments(args []string) string

Take a list of strings and escape them so they will be handled right when passed as arguments to an program via a shell

func StdCopy added in v0.6.4

func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, err error)

StdCopy is a modified version of io.Copy.

StdCopy will demultiplex `src`, assuming that it contains two streams, previously multiplexed together using a StdWriter instance. As it reads from `src`, StdCopy will write to `dstout` and `dsterr`.

StdCopy will read until it hits EOF on `src`. It will then return a nil error. In other words: if `err` is non nil, it indicates a real underlying error.

`written` will hold the total number of bytes written to `dstout` and `dsterr`.

func TestDirectory added in v0.6.7

func TestDirectory(templateDir string) (dir string, err error)

TestDirectory creates a new temporary directory and returns its path. The contents of directory at path `templateDir` is copied into the new directory.

func TreeSize added in v0.7.0

func TreeSize(dir string) (size int64, err error)

TreeSize walks a directory tree and returns its total size in bytes.

func Trunc

func Trunc(s string, maxlen int) string

func TruncateID added in v0.4.1

func TruncateID(id string) string

TruncateID returns a shorthand version of a string identifier for convenience. A collision with other shorthands is very unlikely, but possible. In case of a collision a lookup with TruncIndex.Get() will fail, and the caller will need to use a langer prefix, or the full-length Id.

func ValidateContextDirectory added in v0.12.0

func ValidateContextDirectory(srcPath string) error

ValidateContextDirectory checks if all the contents of the directory can be read and returns an error if some files can't be read symlinks which point to non-existing files don't trigger an error

func ValidateID added in v0.10.0

func ValidateID(id string) error

func WriteLog added in v0.11.0

func WriteLog(src io.Reader, dst io.WriteCloser, format string) error

Types

type CheckSum added in v0.9.0

type CheckSum struct {
	io.Reader
	Hash hash.Hash
}

func (*CheckSum) Read added in v0.9.0

func (cs *CheckSum) Read(buf []byte) (int, error)

func (*CheckSum) Sum added in v0.9.0

func (cs *CheckSum) Sum() string

type Fataler added in v0.6.7

type Fataler interface {
	Fatal(args ...interface{})
}

A common interface to access the Fatal method of both testing.B and testing.T.

type HTTPAuthDecorator added in v0.7.1

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

func (*HTTPAuthDecorator) ChangeRequest added in v0.7.1

func (self *HTTPAuthDecorator) ChangeRequest(req *http.Request) (*http.Request, error)

type HTTPMetaHeadersDecorator added in v0.6.1

type HTTPMetaHeadersDecorator struct {
	Headers map[string][]string
}

func (*HTTPMetaHeadersDecorator) ChangeRequest added in v0.6.1

func (h *HTTPMetaHeadersDecorator) ChangeRequest(req *http.Request) (newReq *http.Request, err error)

type HTTPRequestDecorator added in v0.6.0

type HTTPRequestDecorator interface {
	// ChangeRequest() changes the request accordingly.
	// The changed request will be returned or err will be non-nil
	// if an error occur.
	ChangeRequest(req *http.Request) (newReq *http.Request, err error)
}

HTTPRequestDecorator is used to change an instance of http.Request. It could be used to add more header fields, change body, etc.

func NewHTTPAuthDecorator added in v0.7.1

func NewHTTPAuthDecorator(login, password string) HTTPRequestDecorator

func NewHTTPUserAgentDecorator added in v0.6.0

func NewHTTPUserAgentDecorator(versions ...VersionInfo) HTTPRequestDecorator

type HTTPRequestFactory added in v0.6.0

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

HTTPRequestFactory creates an HTTP request and applies a list of decorators on the request.

func NewHTTPRequestFactory added in v0.6.0

func NewHTTPRequestFactory(d ...HTTPRequestDecorator) *HTTPRequestFactory

func (*HTTPRequestFactory) AddDecorator added in v0.7.1

func (self *HTTPRequestFactory) AddDecorator(d ...HTTPRequestDecorator)

func (*HTTPRequestFactory) NewRequest added in v0.6.0

func (h *HTTPRequestFactory) NewRequest(method, urlStr string, body io.Reader, d ...HTTPRequestDecorator) (*http.Request, error)

NewRequest() creates a new *http.Request, applies all decorators in the HTTPRequestFactory on the request, then applies decorators provided by d on the request.

type HTTPUserAgentDecorator added in v0.6.0

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

HTTPUserAgentDecorator appends the product/version to the user agent field of a request.

func (*HTTPUserAgentDecorator) ChangeRequest added in v0.6.0

func (h *HTTPUserAgentDecorator) ChangeRequest(req *http.Request) (newReq *http.Request, err error)

type JSONError added in v0.6.0

type JSONError struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

func (*JSONError) Error added in v0.6.0

func (e *JSONError) Error() string

type JSONLog added in v0.5.1

type JSONLog struct {
	Log     string    `json:"log,omitempty"`
	Stream  string    `json:"stream,omitempty"`
	Created time.Time `json:"time"`
}

func (*JSONLog) Format added in v0.11.0

func (jl *JSONLog) Format(format string) (string, error)

type JSONMessage added in v0.4.1

type JSONMessage struct {
	Stream          string        `json:"stream,omitempty"`
	Status          string        `json:"status,omitempty"`
	Progress        *JSONProgress `json:"progressDetail,omitempty"`
	ProgressMessage string        `json:"progress,omitempty"` //deprecated
	ID              string        `json:"id,omitempty"`
	From            string        `json:"from,omitempty"`
	Time            int64         `json:"time,omitempty"`
	Error           *JSONError    `json:"errorDetail,omitempty"`
	ErrorMessage    string        `json:"error,omitempty"` //deprecated
}

func (*JSONMessage) Display added in v0.5.1

func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error

type JSONMessageListener added in v1.0.1

type JSONMessageListener chan<- JSONMessage

type JSONMessagePublisher added in v1.0.1

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

func NewJSONMessagePublisher added in v1.0.1

func NewJSONMessagePublisher() *JSONMessagePublisher

func (*JSONMessagePublisher) Publish added in v1.0.1

func (p *JSONMessagePublisher) Publish(m JSONMessage)

func (*JSONMessagePublisher) Subscribe added in v1.0.1

func (p *JSONMessagePublisher) Subscribe(l JSONMessageListener)

func (*JSONMessagePublisher) SubscribersCount added in v1.0.1

func (p *JSONMessagePublisher) SubscribersCount() int

func (*JSONMessagePublisher) Unsubscribe added in v1.0.1

func (p *JSONMessagePublisher) Unsubscribe(l JSONMessageListener) bool

Unsubscribe closes and removes the specified listener from the list of previously registed ones. It returns a boolean value indicating if the listener was successfully found, closed and unregistered.

type JSONProgress added in v0.7.1

type JSONProgress struct {
	Current int   `json:"current,omitempty"`
	Total   int   `json:"total,omitempty"`
	Start   int64 `json:"start,omitempty"`
	// contains filtered or unexported fields
}

func (*JSONProgress) String added in v0.7.1

func (p *JSONProgress) String() string

type KernelVersionInfo

type KernelVersionInfo struct {
	Kernel int
	Major  int
	Minor  int
	Flavor string
}

func GetKernelVersion

func GetKernelVersion() (*KernelVersionInfo, error)

func ParseRelease added in v0.6.2

func ParseRelease(release string) (*KernelVersionInfo, error)

func (*KernelVersionInfo) String

func (k *KernelVersionInfo) String() string

type KeyValuePair added in v0.10.0

type KeyValuePair struct {
	Key   string
	Value string
}

type LogFormatter added in v0.11.0

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

type NopFlusher

type NopFlusher struct{}

func (*NopFlusher) Flush

func (f *NopFlusher) Flush()

type NopWriter

type NopWriter struct{}

func (*NopWriter) Write

func (*NopWriter) Write(buf []byte) (int, error)

type StatusError added in v0.6.2

type StatusError struct {
	Status     string
	StatusCode int
}

An StatusError reports an unsuccessful exit by a command.

func (*StatusError) Error added in v0.6.2

func (e *StatusError) Error() string

type StdType added in v0.6.4

type StdType [StdWriterPrefixLen]byte
var (
	Stdin  StdType = StdType{0: 0}
	Stdout StdType = StdType{0: 1}
	Stderr StdType = StdType{0: 2}
)

type StdWriter added in v0.6.4

type StdWriter struct {
	io.Writer
	// contains filtered or unexported fields
}

func NewStdWriter added in v0.6.4

func NewStdWriter(w io.Writer, t StdType) *StdWriter

NewStdWriter instanciates a new Writer. Everything written to it will be encapsulated using a custom format, and written to the underlying `w` stream. This allows multiple write streams (e.g. stdout and stderr) to be muxed into a single connection. `t` indicates the id of the stream to encapsulate. It can be utils.Stdin, utils.Stdout, utils.Stderr.

func (*StdWriter) Write added in v0.6.4

func (w *StdWriter) Write(buf []byte) (n int, err error)

type StderrFormater added in v0.10.0

type StderrFormater struct {
	io.Writer
	*StreamFormatter
}

func (*StderrFormater) Write added in v0.10.0

func (sf *StderrFormater) Write(buf []byte) (int, error)

type StdoutFormater added in v0.10.0

type StdoutFormater struct {
	io.Writer
	*StreamFormatter
}

func (*StdoutFormater) Write added in v0.10.0

func (sf *StdoutFormater) Write(buf []byte) (int, error)

type StreamFormatter added in v0.4.0

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

func NewStreamFormatter added in v0.4.0

func NewStreamFormatter(json bool) *StreamFormatter

func (*StreamFormatter) FormatError added in v0.4.0

func (sf *StreamFormatter) FormatError(err error) []byte

func (*StreamFormatter) FormatProgress added in v0.4.0

func (sf *StreamFormatter) FormatProgress(id, action string, progress *JSONProgress) []byte

func (*StreamFormatter) FormatStatus added in v0.4.0

func (sf *StreamFormatter) FormatStatus(id, format string, a ...interface{}) []byte

func (*StreamFormatter) FormatStream added in v0.7.1

func (sf *StreamFormatter) FormatStream(str string) []byte

func (*StreamFormatter) Json added in v0.8.0

func (sf *StreamFormatter) Json() bool

type TarSum added in v0.6.0

type TarSum struct {
	io.Reader

	DisableCompression bool
	// contains filtered or unexported fields
}

func (*TarSum) GetSums added in v0.7.3

func (ts *TarSum) GetSums() map[string]string

func (*TarSum) Read added in v0.6.0

func (ts *TarSum) Read(buf []byte) (int, error)

func (*TarSum) Sum added in v0.6.0

func (ts *TarSum) Sum(extra []byte) string

type TimeoutConn added in v0.12.0

type TimeoutConn struct {
	net.Conn
	// contains filtered or unexported fields
}

A net.Conn that sets a deadline for every Read or Write operation

func (*TimeoutConn) Read added in v0.12.0

func (c *TimeoutConn) Read(b []byte) (int, error)

type Utsname

type Utsname syscall.Utsname

type VersionInfo added in v0.6.0

type VersionInfo interface {
	Name() string
	Version() string
}

VersionInfo is used to model entities which has a version. It is basically a tupple with name and version.

type WriteBroadcaster

type WriteBroadcaster struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewWriteBroadcaster

func NewWriteBroadcaster() *WriteBroadcaster

func (*WriteBroadcaster) AddWriter

func (w *WriteBroadcaster) AddWriter(writer io.WriteCloser, stream string)

func (*WriteBroadcaster) CloseWriters

func (w *WriteBroadcaster) CloseWriters() error

func (*WriteBroadcaster) Write

func (w *WriteBroadcaster) Write(p []byte) (n int, err error)

type WriteFlusher

type WriteFlusher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewWriteFlusher

func NewWriteFlusher(w io.Writer) *WriteFlusher

func (*WriteFlusher) Flush added in v0.6.6

func (wf *WriteFlusher) Flush()

Flush the stream immediately.

func (*WriteFlusher) Write

func (wf *WriteFlusher) Write(b []byte) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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