utility

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2017 License: MIT Imports: 10 Imported by: 2

README

utility : Utility functions for go projects

GoDoc Go Report Card

Overview

This is a small library of utility functions

Install

go get github.com/dstroot/utility

License

MIT.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcSettlementDate

func CalcSettlementDate(today time.Time, bankHolidayMap map[string]bool) time.Time

CalcSettlementDate takes in today's date (basically "now") along with a a map of bank holidays and it calculates to correct settlement date for ACH transactions.

func Check

func Check(e error)

Check streamlines error checks - use it *only* when the program should halt

func Float64Equal

func Float64Equal(a, b float64) bool

Float64Equal checks not whether the numbers are exactly the same, but whether their difference is very small. The error margin that the difference is compared to is called epsilon.

func GenRandomString

func GenRandomString(strlen int) string

GenRandomString returns a hexadecimal random string

func GetLocalIP

func GetLocalIP() (ip string, err error)

GetLocalIP returns the non-loopback local IP of the host

func MakeFileName

func MakeFileName(fileExtension string, directory string) string

MakeFileName creates a new filename

func Padding

func Padding(s string, length int, justified string, padChar string) (string, error)

Padding takes a string, length and either "left" or "right" for padding/justification plus a padding character. It will pad the string out.

func RoundDuration

func RoundDuration(d, r time.Duration) time.Duration

RoundDuration rounds time.Duration Example to seconds: RoundDuration(d, time.Second)

func RoundFloat64

func RoundFloat64(val float64, places int) float64

RoundFloat64 rounds numbers

func SliceIndex

func SliceIndex(limit int, predicate func(i int) bool) (int, error)

SliceIndex figures out the index of slice given a value in the slice. http://stackoverflow.com/questions/8307478/go-how-to-find-out-element-position-in-slice It's used to find the slice position of the process activity step. Then we use that to calculate the next action. Usage: xs := []int{2, 4, 6, 8} ys := []string{"C", "B", "K", "A"} fmt.Println(

SliceIndex(len(xs), func(i int) bool { return xs[i] == 5 }),
SliceIndex(len(xs), func(i int) bool { return xs[i] == 6 }),
SliceIndex(len(ys), func(i int) bool { return ys[i] == "Z" }),
SliceIndex(len(ys), func(i int) bool { return ys[i] == "A" }))

Types

This section is empty.

Jump to

Keyboard shortcuts

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