lax

package
v0.0.0-...-fb9b9fb Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2017 License: MIT Imports: 15 Imported by: 0

README

lax

A collection of Go functions that the authors seem to use frequently enough to warrant a folder-like package. Here lax is short for relax or perhaps as one developer put it: lazy

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDays

func AddDays(d time.Time, n int) time.Time

AddDays adds the given number of days to the given date. The number of days can be negative.

func AllFilesUnderDir

func AllFilesUnderDir(dir string) []string

AllFilesUnderDir returns a list of all filenames that exist under the supplied directory. If the supplied directory does not exist then it returns an empty list.

func Append

func Append(filename string, label string) *os.File

Append a file. alert.Exit on failure

func CopyFile

func CopyFile(fromPath, toPath, label string)

CopyFile copies a given file. alert.Exit on failure (via WriteFile)

func Create

func Create(filename string, label string) *os.File

Create a file. alert.Exit on failure.

func DaysBetween

func DaysBetween(bgn time.Time, end time.Time) int

DaysBetween returns the number of days between the two dates. Remember that the difference between a date and itself is zero.

func ExecPath

func ExecPath() string

ExecPath returns a string containing the full executable path.

func F32toa

func F32toa(f float32) string

F32toa converts a float32 into a string. This is simply a convenience wrapper around `strconv.FormatFloat`.

func F64toa

func F64toa(f float64) string

F64toa converts a float64 into a string. This is simply a convenience wrapper around `strconv.FormatFloat`.

func FileExists

func FileExists(filename string) bool

FileExists return true of the supplied filename exists

func FileLen

func FileLen(filename string) int64

FileLen returns the length of a file

func FileMode

func FileMode(filename string) (os.FileMode, error)

FileMode returns the file-mode of the supplied filename.

func HasS

func HasS(list []string, str string) bool

HasS returns true if the supplied slice contains the supplied string

func Heading

func Heading(label string, dashes int) string

Heading returns a pretty separator with the given label

func Hostname

func Hostname() string

Hostname returns a string containing the hostname. Returns the value "unknown_host" on failure

func InTimeRange

func InTimeRange(t time.Time, bgn time.Time, end time.Time) bool

InTimeRange returns true if the first time is between the second and third times inclusive

func IsDir

func IsDir(path string) bool

IsDir returns true if the supplied path is a directory (as opposed to a file)

func IsFile

func IsFile(path string) bool

IsFile returns true if the supplied path is a file (as opposed to a directory)

func MakeDate

func MakeDate(yyyymmdd int) time.Time

MakeDate converts a date in literal-integer format (i.e. 2015-06-01 is represented by the integer 20150601) to a time.Time value in the local timezone.

func MakeDateI

func MakeDateI(yyyymmdd int) time.Time

MakeDateI converts a date in literal-integer format (i.e. 2015-06-01 is represented by the integer 20150601) to a time.Time value in the local timezone.

func MakeDateList

func MakeDateList(bgn time.Time, end time.Time) []time.Time

MakeDateList returns a list of consecutive dates starting and ending on the given dates (inclusive)

func MakeDateS

func MakeDateS(s string) time.Time

MakeDateS converts a date from string formats "2015-06-01" and "20150601" to a time.Time value. The time will be midnight UTC.

func MkDir

func MkDir(dir string, label string)

MkDir creates a directory (including all parents i.e. mkdir -p) alert.Exit on failure)

func NowDate

func NowDate() time.Time

NowDate returns the current date

func Open

func Open(filename string) *os.File

Open a file. alert.Exit on failure.

func ParseFloat64

func ParseFloat64(str string) float64

ParseFloat64 parses a string and returns a float64. On failure it displays an error message and calls exit.

func ParseUint32

func ParseUint32(str string) uint32

ParseUint32 parses a string and returns a uint32. On failure it displays an error message and calls exit.

func ReadFile

func ReadFile(filename string, label string) string

ReadFile reads a file and returns the contents as a string. alert.Exit on failure.

func ReadYAML

func ReadYAML(filename string, config interface{})

ReadYAML reads a YAML file into an arbitrary structure.

func Separator

func Separator(length int) string

Separator returns a string of dashes (for displaying).

func SideBySide

func SideBySide(a string, b string, divider string) string

SideBySide takes two (multi-line) strings and returns a string that displays them side by side:

Apple Pear Banana Grapefruit Canteloupe

They do not have to have the same number of lines

func SortI

func SortI(s []int)

SortI sorts a slice of integers

func SortS

func SortS(s []string)

SortS sorts a slice of strings

func StackTrace

func StackTrace(depth int) string

StackTrace returns a string containing stack-trace information up to the supplied depth. Supplying a depth of zero results in a full stack-trace.

func StripColors

func StripColors(s string) string

StripColors returns a string by removing color-coding characters from the supplied string

func SubDays

func SubDays(d time.Time, n int) time.Time

SubDays subtracts the given number of days to the given date. The number of days can be negative.

func U32toa

func U32toa(u uint32) string

U32toa converts a uint32 into a string.

func Username

func Username() string

Username returns a string containing the current user. Returns the value "unknown_user" on failure

func WriteFile

func WriteFile(filename, body, label string)

WriteFile writes a string to file. If a file with that name exists, it will overwrite it. alert.Exit on failure.

Types

This section is empty.

Jump to

Keyboard shortcuts

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