util

package
v0.0.0-...-92255fb Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2017 License: MIT Imports: 4 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyError

func AnyError(errs ...error) error

AnyError checks each of the provided errors and returns the first one that is not nil. If all of them are nil, this function returns nil.

func Atoi

func Atoi(str string) int

Atoi converts a string into an integer, returning 0 upon error.

func Atoi64

func Atoi64(str string) int64

Atoi64 converts a string into a 64-bit integer, returning 0 upon error.

func ContainsInt

func ContainsInt(integers []int, v int) bool

ContainsInt determines whether the integer slice contains the specified integer.

func ContainsString

func ContainsString(str string, terms []string, caseSensitive bool) bool

ContainsString searches the provided string to see if it contains *any* of the provided search terms. The caseSensitive parameter is used to determine if the matches should be case sensitive.

func FilterInt

func FilterInt(integers []int, fn func(int) bool) (newIntegers []int)

FilterInt executes the provided function for each integer in the slice and only includes it in the slice returned if the function returns true.

func LoadJSON

func LoadJSON(name string, v interface{}) (bool, error)

Load a JSON file from disk if it exists. The first value returned is true if the file existed and false if it did not (default values should be set).

func SaveJSON

func SaveJSON(name string, v interface{}) error

Save writes the JSON file to disk.

func SplitAndTrimString

func SplitAndTrimString(str, separator string) []string

SplitAndTrimString splits a string using the provided separator and then trims spaces from each of the strings.

func Truncate

func Truncate(message string, maxLen int) string

Truncate ensures that a message consists of less than 140 characters, appending an ellipsis if necessary.

Types

This section is empty.

Jump to

Keyboard shortcuts

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