util

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package util haters gonna hate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasePath

func BasePath(s string) string

BasePath returns a normalized base path, stripping the leading '/' if present.

func Camelcase

func Camelcase(s string, v ...interface{}) string

Camelcase string with optional args.

func CertDomainNames

func CertDomainNames(s string) []string

CertDomainNames returns the certificate domain name and alternative names for a requested domain.

func ClearHeader

func ClearHeader(h http.Header)

ClearHeader removes all content header fields.

func DateSuffix

func DateSuffix(t time.Time) string

DateSuffix returns the date suffix for t.

func DecodeAlias

func DecodeAlias(s string) string

DecodeAlias decodes an alias string which was encoded by the EncodeAlias function.

func Domain

func Domain(s string) string

Domain returns the effective domain (TLD plus one).

func EncodeAlias

func EncodeAlias(s string) string

EncodeAlias encodes an alias string so that it conforms to the requirement of matching (?!^[0-9]+$)([a-zA-Z0-9-_]+).

func Env

func Env(m map[string]string) (env []string)

Env returns a slice from environment variable map.

func Exists

func Exists(path string) bool

Exists returns true if the file exists.

func ExitStatus

func ExitStatus(cmd *exec.Cmd, err error) string

ExitStatus returns the exit status of cmd.

func Fatal

func Fatal(err error)

Fatal error.

func FixMultipleSetCookie

func FixMultipleSetCookie(h http.Header)

FixMultipleSetCookie staggers the casing of each set-cookie value to trick API Gateway into setting multiple in the response.

func Indent

func Indent(s string) string

Indent the given string.

func IsBucketExists

func IsBucketExists(err error) bool

IsBucketExists returns true if err is not nil and represents an existing bucket.

func IsCI

func IsCI() bool

IsCI returns true if the env looks like it's a CI platform.

func IsJSON

func IsJSON(s string) bool

IsJSON returns true if the string looks like json.

func IsJSONLog

func IsJSONLog(s string) bool

IsJSONLog returns true if the string looks likes a json log.

func IsListening

func IsListening(u *url.URL) bool

IsListening returns true if there's a server listening on `u`.

func IsNoCredentials

func IsNoCredentials(err error) bool

IsNoCredentials returns true if err is not nil and represents missing credentials.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if err is not nil and represents a missing resource.

func IsThrottled

func IsThrottled(err error) bool

IsThrottled returns true if err is not nil and represents a throttled request.

func IsWildcardDomain

func IsWildcardDomain(s string) bool

IsWildcardDomain returns true if the domain is a wildcard.

func Log

func Log(msg string, v ...interface{})

Log outputs a log message.

func LogClear

func LogClear(msg string, v ...interface{})

LogClear clears the line and outputs a log message.

func LogListItem

func LogListItem(msg string, v ...interface{})

LogListItem outputs a list item.

func LogName

func LogName(name, msg string, v ...interface{})

LogName outputs a log message with name.

func LogPad

func LogPad(msg string, v ...interface{})

LogPad outputs a log message with padding.

func LogTitle

func LogTitle(msg string, v ...interface{})

LogTitle outputs a log title.

func ManagedByUp

func ManagedByUp(s string) string

ManagedByUp appends "Managed by Up".

func Md5

func Md5(s string) string

Md5 returns an md5 hash for s.

func Milliseconds

func Milliseconds(d time.Duration) int

Milliseconds returns the duration as milliseconds.

func MillisecondsSince

func MillisecondsSince(t time.Time) int

MillisecondsSince returns the duration as milliseconds relative to time t.

func NewInlineProgressInt

func NewInlineProgressInt(total int) *progress.Bar

NewInlineProgressInt with the given total.

func NewProgressInt

func NewProgressInt(total int) *progress.Bar

NewProgressInt with the given total.

func Pad

func Pad() func()

Pad helper.

func ParseDuration

func ParseDuration(s string) (d time.Duration, err error)

ParseDuration string with day and month approximation support.

func ParseSections

func ParseSections(r io.Reader) (sections []string, err error)

ParseSections returns INI style sections from r.

func PrefixLines

func PrefixLines(s string, prefix string) string

PrefixLines prefixes the lines in s with prefix.

func ReadFileJSON

func ReadFileJSON(path string, v interface{}) error

ReadFileJSON reads json from the given path.

func RemoveSubdomains

func RemoveSubdomains(s string, n int) string

RemoveSubdomains returns the domain without the n left-most subdomain(s).

func StringsContains

func StringsContains(list []string, s string) bool

StringsContains returns true if list contains s.

func StripLerna

func StripLerna(s string) string

StripLerna strips the owner portion of a Lerna-based tag. See #670 for details. They are in the form of "@owner/repo@0.5.0".

func ToFloat

func ToFloat(v interface{}) float64

ToFloat returns a float or NaN.

func UniqueStrings

func UniqueStrings(s []string) (v []string)

UniqueStrings returns a string slice of unique values.

func WaitForListen

func WaitForListen(u *url.URL, timeout time.Duration) error

WaitForListen blocks until `u` is listening with timeout.

func WildcardMatches

func WildcardMatches(wildcard, domain string) bool

WildcardMatches returns true if wildcard is a wildcard domain and it satisfies the given domain.

Types

This section is empty.

Jump to

Keyboard shortcuts

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