util

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AskForConfirmation

func AskForConfirmation() bool

AskForConfirmation requests a y/n from user.

func CheckClose

func CheckClose(c io.Closer)

CheckClose is used to check the return from Close in a defer statement. From https://groups.google.com/d/msg/golang-nuts/-eo7navkp10/BY3ym_vMhRcJ

func CheckErr

func CheckErr(err error)

CheckErr exits with a log.Fatal() if an error is encountered. It is normally used for errors that we never expect to happen, and don't have any normal handling technique. From https://davidnix.io/post/error-handling-in-go/

func DownloadFile

func DownloadFile(fp string, url string, progressBar bool) (err error)

DownloadFile retrieves a file.

func EnsureHTTPStatus

func EnsureHTTPStatus(o *HTTPOptions) error

EnsureHTTPStatus will verify a URL responds with a given response code within the Timeout period (in seconds)

func Error

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

Error will print an red error message but will not exit.

func Failed

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

Failed will print a red error message and exit with failure.

func FormatPlural

func FormatPlural(count int, single string, plural string) string

FormatPlural is a simple wrapper which returns different strings based on the count value.

func GetGlobalDdevDir

func GetGlobalDdevDir() string

GetGlobalDdevDir returns ~/.ddev, the global caching directory

func GetInput

func GetInput(defaultValue string) string

GetInput reads input from an input buffer and returns the result as a string.

func IsPortActive added in v0.12.0

func IsPortActive(port string) bool

IsPortActive checks to see if the given port on docker IP is answering.

func MapKeysToArray added in v1.1.0

func MapKeysToArray(mapWithKeys map[string]interface{}) []string

MapKeysToArray takes the keys of the map and turns them into a string array

func Prompt added in v1.1.0

func Prompt(prompt string, defaultValue string) string

Prompt gets input with a prompt and returns the input

func RandString

func RandString(n int) string

RandString returns a random string of given length n.

func SetInputScanner

func SetInputScanner(scanner *bufio.Scanner)

SetInputScanner allows you to override the default input scanner with your own.

func SetLetterBytes added in v1.1.0

func SetLetterBytes(lb string)

SetLetterBytes exists solely so that tests can override the default characters used by RandString. It should probably be avoided for 'normal' operations. this is actually used in utils_test.go (test only) so we set nolint on it. nolint: deadcode

func Success

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

Success will indicate an operation succeeded with colored confirmation text.

func Warning

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

Warning will present the user with warning text.

Types

type HTTPOptions

type HTTPOptions struct {
	URL            string
	Username       string
	Password       string
	Timeout        time.Duration
	TickerInterval time.Duration
	ExpectedStatus int
	Headers        map[string]string
}

HTTPOptions defines the URL and other common HTTP options for EnsureHTTPStatus.

func NewHTTPOptions

func NewHTTPOptions(URL string) *HTTPOptions

NewHTTPOptions returns a new HTTPOptions struct with some sane defaults.

Jump to

Keyboard shortcuts

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