gtools

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: MIT Imports: 3 Imported by: 3

README

GoDoc Build Status Go Report Card codecov

go-tools

a collection of useful go libraries

uri

a convenient and easy way to unmarshal a uri to a struct.

This has been migrated to its own repo see [https://github.com/jbsmith7741/uri]

appenderr

A lot of times we have functions that have multiple error checks in them. Sometimes its helpful to be able to lot at full set of errors rather than the first occurring error. AppendErr is an easy way to add multiple errors together and return the whole set in a single error interface. appenderr is thread safe and can be used to collect errors that occur in different go routines. Each error is counted (based on the string value) and displayed on it's own line.

// Checkline verifies that the line is a list of comma separated integers.
// It returns a list of invalid fields if any exist
func CheckLine(line string)  error {
    errs := appenderr.New() 
    for _, v := range strings.Split(line, ",") {
        _, err := strconv.Atoi(v)
        errs.Add(err)
    }
    return errs.ErrOrNil()
}

sqlh

a sql helper class that simplifies configs and connections to databases. sqlh removes the need for anonymous imports and allows basic testing of database calls without having to worry about connecting to a real database.

sqlh should be used to test around database calls and not to test the calls themselves. If you need to test the database logic use sqlmock

gtools

temporary holding spot for tools i find helpful

  • PerciseFloat - usefully for truncating off unnecessary digits of a float.
  • PrintDuration - extends standard lib duration string printing by adding day and year and includes 2 digits truncation on second.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PreciseFloat

func PreciseFloat(f float64, digits int) float64

PreciseFloat truncates a float to the specified number of digits

func PrintDuration added in v0.4.0

func PrintDuration(d time.Duration) (s string)

PrintDuration converts a duration into a human friendly time

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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