util

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2015 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package util provides utility functions for the cmd packages.

Index

Constants

This section is empty.

Variables

View Source
var ErrorNoDefaultIP = errors.New("no suitable IP address")

NoDefaultIP means no suitable non-loopback address can be found.

Functions

func AllLocalIP4 added in v0.5.1

func AllLocalIP4() ([]net.IP, error)

AllLocalIP4 returns all the IPv4 addresses that this host can be reached on.

func CertPoolFromFile added in v0.4.3

func CertPoolFromFile(filename string) (*x509.CertPool, error)

func CertificatesFromFile added in v0.4.3

func CertificatesFromFile(file string) ([]*x509.Certificate, error)

func CertificatesFromPEM added in v0.4.3

func CertificatesFromPEM(pemCerts []byte) ([]*x509.Certificate, error)

func DefaultLocalIP4

func DefaultLocalIP4() (net.IP, error)

DefaultLocalIP4 returns an IPv4 address that this host can be reached on. Will return NoDefaultIP if no suitable address can be found.

func Env

func Env(key string, defaultValue string) string

Env returns an environment variable or a default value if not specified.

func EnvInt added in v0.4.2

func EnvInt(key string, defaultValue int32, minValue int32) int32

func GetEnv

func GetEnv(key string) (string, bool)

GetEnv returns an environment value if specified

func GetLogLevel added in v0.4.2

func GetLogLevel() (level int)

GetLogLevel returns the current glog log level

func IsEnvironmentArgument added in v0.3.1

func IsEnvironmentArgument(s string) bool

func IsTerminal added in v0.4.2

func IsTerminal(r io.Reader) bool

func MakeAbs added in v0.4.2

func MakeAbs(path, base string) (string, error)

func MakeRelative added in v0.4.4

func MakeRelative(path, base string) (string, error)

func PromptForBool added in v0.4.2

func PromptForBool(r io.Reader, format string, a ...interface{}) bool

Prompt for user input of a boolean value. The accepted values are:

yes, y, true, 	t, 1 (not case sensitive)
no, 	n, false, f, 0 (not case sensitive)

A valid answer is mandatory so it will keep asking until an answer is provided.

func PromptForPasswordString added in v0.3.1

func PromptForPasswordString(r io.Reader, format string, a ...interface{}) string

Prompt for user input by disabling echo in terminal, useful for password prompt.

func PromptForString added in v0.3.1

func PromptForString(r io.Reader, format string, a ...interface{}) string

Takes an io.Reader and prompt for user input if it's a terminal, returning the result.

func PromptForStringWithDefault added in v0.4.2

func PromptForStringWithDefault(r io.Reader, def string, format string, a ...interface{}) string

Prompt for user input but take a default in case nothing is provided.

func RelativizePathWithNoBacksteps added in v0.4.2

func RelativizePathWithNoBacksteps(refs []*string, base string) error

RelativizePathWithNoBacksteps updates the given refs to be relative paths, relative to the given base directory as long as they do not require backsteps. Any path requiring a backstep is left as-is as long it is absolute. Any non-absolute path that can't be relativized produces an error

func RelativizePaths added in v0.4.2

func RelativizePaths(refs []*string, base string) error

RelativizePaths updates the given refs to be relative paths, relative to the given base directory

func ResolvePaths added in v0.4.2

func ResolvePaths(refs []*string, base string) error

ResolvePaths updates the given refs to be absolute paths, relative to the given base directory

func TransportFor added in v0.4.3

func TransportFor(ca string, certFile string, keyFile string) (http.RoundTripper, error)

TransportFor returns an http.Transport for the given ca and client cert (which may be empty strings)

func TryListen added in v0.4.2

func TryListen(hostPort string) (bool, error)

TryListen tries to open a connection on the given port and returns true if it succeeded.

func WaitForSuccessfulDial

func WaitForSuccessfulDial(https bool, network, address string, timeout, interval time.Duration, retries int) error

WaitForDial attempts to connect to the given address, closing and returning nil on the first successful connection.

Types

type Environment added in v0.3.1

type Environment map[string]string

func ParseEnvironmentArguments added in v0.3.1

func ParseEnvironmentArguments(s []string) (Environment, []string, []error)

type Mux

type Mux interface {
	Handle(pattern string, handler http.Handler)
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
}

Mux is a standard mux interface for HTTP

type Output added in v0.5.1

type Output struct {
	Out io.Writer
}

func (Output) Get added in v0.5.1

func (o Output) Get() io.Writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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