Documentation ¶
Overview ¶
Package util provides utility functions for the cmd packages.
Index ¶
- Variables
- func AllLocalIP4() ([]net.IP, error)
- func CertPoolFromFile(filename string) (*x509.CertPool, error)
- func CertificatesFromFile(file string) ([]*x509.Certificate, error)
- func CertificatesFromPEM(pemCerts []byte) ([]*x509.Certificate, error)
- func DefaultLocalIP4() (net.IP, error)
- func DefaultSubCommandRun(out io.Writer) func(c *cobra.Command, args []string)
- func Env(key string, defaultValue string) string
- func EnvInt(key string, defaultValue int32, minValue int32) int32
- func GetDisplayFilename(filename string) string
- func GetEnv(key string) (string, bool)
- func GetLogLevel() (level int)
- func IsEnvironmentArgument(s string) bool
- func IsTerminal(r io.Reader) bool
- func IsTerminalWriter(w io.Writer) bool
- func ListenAndServe(srv *http.Server, network string) error
- func ListenAndServeTLS(srv *http.Server, network string, certFile, keyFile string) error
- func MakeAbs(path, base string) (string, error)
- func MakeRelative(path, base string) (string, error)
- func PromptForBool(r io.Reader, w io.Writer, format string, a ...interface{}) bool
- func PromptForPasswordString(r io.Reader, w io.Writer, format string, a ...interface{}) string
- func PromptForString(r io.Reader, w io.Writer, format string, a ...interface{}) string
- func PromptForStringWithDefault(r io.Reader, w io.Writer, def string, format string, a ...interface{}) string
- func RelativizePathWithNoBacksteps(refs []*string, base string) error
- func RelativizePaths(refs []*string, base string) error
- func ResolvePaths(refs []*string, base string) error
- func TransportFor(ca string, certFile string, keyFile string) (http.RoundTripper, error)
- func TryListen(network, hostPort string) (bool, error)
- func WaitForSuccessfulDial(https bool, network, address string, timeout, interval time.Duration, ...) error
- type Environment
- type Mux
Constants ¶
This section is empty.
Variables ¶
var ErrorNoDefaultIP = errors.New("no suitable IP address")
ErrorNoDefaultIP is returned when no suitable non-loopback address can be found.
Functions ¶
func AllLocalIP4 ¶ added in v0.5.1
AllLocalIP4 returns all the IPv4 addresses that this host can be reached on.
func CertPoolFromFile ¶ added in v0.4.3
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 ¶
DefaultLocalIP4 returns an IPv4 address that this host can be reached on. Will return NoDefaultIP if no suitable address can be found.
func DefaultSubCommandRun ¶ added in v0.5.4
func GetDisplayFilename ¶ added in v1.0.6
GetDisplayFilename returns the absolute path of the filename as long as there was no error, otherwise it returns the filename as-is
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 IsTerminal ¶ added in v0.4.2
IsTerminal returns whether the passed io.Reader is a terminal or not
func IsTerminalWriter ¶ added in v1.0.1
IsTerminalWriter returns whether the passed io.Writer is a terminal or not
func ListenAndServe ¶ added in v1.0.5
ListenAndServe starts a server that listens on the provided TCP mode (as supported by net.Listen)
func ListenAndServeTLS ¶ added in v1.0.5
ListenAndServeTLS starts a server that listens on the provided TCP mode (as supported by net.Listen).
func MakeRelative ¶ added in v0.4.4
func PromptForBool ¶ added in v0.4.2
PromptForBool prompts 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
PromptForPasswordString prompts for user input by disabling echo in terminal, useful for password prompt.
func PromptForString ¶ added in v0.3.1
PromptForString takes an io.Reader and prompts for user input if it's a terminal, returning the result.
func PromptForStringWithDefault ¶ added in v0.4.2
func PromptForStringWithDefault(r io.Reader, w io.Writer, def string, format string, a ...interface{}) string
PromptForStringWithDefault prompts for user input but take a default in case nothing is provided.
func RelativizePathWithNoBacksteps ¶ added in v0.4.2
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
RelativizePaths updates the given refs to be relative paths, relative to the given base directory
func ResolvePaths ¶ added in v0.4.2
ResolvePaths updates the given refs to be absolute paths, relative to the given base directory
func TransportFor ¶ added in v0.4.3
TransportFor returns an http.Transport for the given ca and client cert (which may be empty strings)
Types ¶
type Environment ¶ added in v0.3.1
func ParseEnvironmentArguments ¶ added in v0.3.1
func ParseEnvironmentArguments(s []string) (Environment, []string, []error)