util

package
v1.15.0-dev Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: MIT Imports: 12 Imported by: 688

Documentation

Index

Constants

View Source
const (
	// OptionalBoolNone a "null" boolean value
	OptionalBoolNone = iota
	// OptionalBoolTrue a "true" boolean value
	OptionalBoolTrue
	// OptionalBoolFalse a "false" boolean value
	OptionalBoolFalse
)

Variables

This section is empty.

Functions

func CopyDir added in v1.14.0

func CopyDir(srcPath, destPath string) error

CopyDir copy files recursively from source to target directory. It returns error when error occurs in underlying functions.

func CopyFile added in v1.14.0

func CopyFile(src, dest string) error

CopyFile copies file from source to target path.

func EnsureAbsolutePath added in v1.3.0

func EnsureAbsolutePath(path string, absoluteBase string) string

EnsureAbsolutePath ensure that a path is absolute, making it relative to absoluteBase if necessary

func ExistsInSlice added in v1.5.0

func ExistsInSlice(target string, slice []string) bool

ExistsInSlice returns true if string exists in slice.

func GetDirectorySize added in v1.11.0

func GetDirectorySize(path string) (int64, error)

GetDirectorySize returns the dumb disk consumption for a given path

func IsDir added in v1.14.0

func IsDir(dir string) (bool, error)

IsDir returns true if given path is a directory, or returns false when it's a file or does not exist.

func IsEmptyString added in v1.7.0

func IsEmptyString(s string) bool

IsEmptyString checks if the provided string is empty

func IsEqualSlice added in v1.5.0

func IsEqualSlice(target []string, source []string) bool

IsEqualSlice returns true if slices are equal.

func IsExist added in v1.14.0

func IsExist(path string) (bool, error)

IsExist checks whether a file or directory exists. It returns false when the file or directory does not exist.

func IsFile added in v1.14.0

func IsFile(filePath string) (bool, error)

IsFile returns true if given path is a file, or returns false when it's a directory or does not exist.

func IsInt64InSlice added in v1.12.0

func IsInt64InSlice(target int64, slice []int64) bool

IsInt64InSlice sequential searches if int64 exists in slice.

func IsSliceInt64Eq added in v1.3.0

func IsSliceInt64Eq(a, b []int64) bool

IsSliceInt64Eq returns if the two slice has the same elements but different sequences.

func IsStringInSlice added in v1.11.0

func IsStringInSlice(target string, slice []string, insensitive ...bool) bool

IsStringInSlice sequential searches if string exists in slice.

func Max added in v1.3.0

func Max(a, b int) int

Max max of two ints

func MergeInto added in v1.14.0

func MergeInto(dict map[string]interface{}, values ...interface{}) (map[string]interface{}, error)

MergeInto merges pairs of values into a "dict"

func Min added in v1.3.0

func Min(a, b int) int

Min min of two ints

func NormalizeEOL added in v1.11.0

func NormalizeEOL(input []byte) []byte

NormalizeEOL will convert Windows (CRLF) and Mac (CR) EOLs to UNIX (LF)

func PaginateSlice added in v1.14.0

func PaginateSlice(list interface{}, page, pageSize int) interface{}

PaginateSlice cut a slice as per pagination options if page = 0 it do not paginate

func PathEscapeSegments added in v1.8.0

func PathEscapeSegments(path string) string

PathEscapeSegments escapes segments of a path while not escaping forward slash

func Remove added in v1.13.0

func Remove(name string) error

Remove removes the named file or (empty) directory with at most 5 attempts.

func RemoveAll added in v1.2.0

func RemoveAll(name string) error

RemoveAll removes the named file or (empty) directory with at most 5 attempts.Remove

func SanitizeMessage added in v1.3.1

func SanitizeMessage(message, unsanitizedURL string) string

SanitizeMessage sanitizes a message which may contains a sensitive URL

func SanitizeURLCredentials added in v1.3.1

func SanitizeURLCredentials(unsanitizedURL string, usePlaceholder bool) string

SanitizeURLCredentials sanitizes a url, either removing user credentials or replacing them with a placeholder.

func ShellEscape added in v1.13.0

func ShellEscape(toEscape string) string

ShellEscape will escape the provided string. We can't just use go-shellquote here because our preferences for escaping differ from those in that we want:

* If the string doesn't require any escaping just leave it as it is. * If the string requires any escaping prefer double quote escaping * If we have ! or newlines then we need to use single quote escaping

func StatDir added in v1.14.0

func StatDir(rootPath string, includeDir ...bool) ([]string, error)

StatDir gathers information of given directory by depth-first. It returns slice of file list and includes subdirectories if enabled; it returns error and nil slice when error occurs in underlying functions, or given path is not a directory or does not exist.

Slice does not include given path itself. If subdirectories is enabled, they will have suffix '/'.

func StopTimer added in v1.11.5

func StopTimer(t *time.Timer) bool

StopTimer is a utility function to safely stop a time.Timer and clean its channel

func URLJoin added in v1.4.3

func URLJoin(base string, elems ...string) string

URLJoin joins url components, like path.Join, but preserving contents

func URLSanitizedError added in v1.3.1

func URLSanitizedError(err error, unsanitizedURL string) error

URLSanitizedError returns the sanitized version an error whose message may contain a sensitive URL

Types

type Int64Slice added in v1.3.0

type Int64Slice []int64

Int64Slice attaches the methods of Interface to []int64, sorting in increasing order.

func (Int64Slice) Len added in v1.3.0

func (p Int64Slice) Len() int

func (Int64Slice) Less added in v1.3.0

func (p Int64Slice) Less(i, j int) bool

func (Int64Slice) Swap added in v1.3.0

func (p Int64Slice) Swap(i, j int)

type OptionalBool

type OptionalBool byte

OptionalBool a boolean that can be "null"

func OptionalBoolOf

func OptionalBoolOf(b bool) OptionalBool

OptionalBoolOf get the corresponding OptionalBool of a bool

func (OptionalBool) IsFalse added in v1.3.0

func (o OptionalBool) IsFalse() bool

IsFalse return true if equal to OptionalBoolFalse

func (OptionalBool) IsNone added in v1.3.0

func (o OptionalBool) IsNone() bool

IsNone return true if equal to OptionalBoolNone

func (OptionalBool) IsTrue added in v1.3.0

func (o OptionalBool) IsTrue() bool

IsTrue return true if equal to OptionalBoolTrue

Jump to

Keyboard shortcuts

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