#golibs
golang functions (to be included in other projects)
go get -u -t simonwaldherr.de/go/golibs/...
go test ./...
| service | info
---|---------|------
| coveralls.io | test coverage
| travis-ci.org | test on various go versions
| appveyor.com | test under windows
| magnum-ci.com | yet another ci service
| | free + open source license
| flattr.com | micro donation
| godoc.org | documentation
##ansi
import "simonwaldherr.de/go/golibs/ansi"
ansi can print colored and styled text to your terminal:
- green, yellow and red strings:
log.Println(ansi.Color("INFO: everything is fine", ansi.Green))
log.Println(ansi.Color("WARNING: not everything is fine", ansi.Yellow))
log.Println(ansi.Color("ERROR: OMG!!!", ansi.Red))
- bold and underlined text:
fmt.Printf("this is %v and %v text", ansi.Bold("bold"), ansi.Underline("underlined"))
##as
import "simonwaldherr.de/go/golibs/as"
with as you can convert most standard data types to most other data types e.g.
- int to string:
var x string = as.String(int(32))
- string to int:
var x int = as.Int("32")
- string to time:
var x time.Time = as.Time("31.12.2014")
##cache
import "simonwaldherr.de/go/golibs/cache"
##file
import "simonwaldherr.de/go/golibs/file"
file wraps around the standard functions to simplify reading and writing on disk
str := "Neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit."
err := file.Write("filename.txt", str, false)
##graphics
import "simonwaldherr.de/go/golibs/graphics"
with graphics you can manipulate images
img := graphics.EachPixel(file, func(r, g, b, a uint8) (uint8, uint8, uint8, uint8) {
return g, b, r, a
})
##re
import "simonwaldherr.de/go/golibs/re"
re helps you whenever you have to do something multiple times
data, stop := re.Do(time.Second * 5, func(data chan<- interface{}) {
data <- fmt.Sprintf("%v\n", time.Now().Format("02.01.2006 15:04:05"))
})
##regex
import "simonwaldherr.de/go/golibs/regex"
regex is a layer to speed up your regular expression development
str := regex.ReplaceAllString("Ipsum Lorem", "([^ ]+) ([^ ]+)", "$2 $1")
##ssl
import "simonwaldherr.de/go/golibs/ssl"
ssl generates ssl certificates for https
err := ssl.Generate(options)
##stack
import "simonwaldherr.de/go/golibs/stack"
with stack you can store your values in stacks and rings
array := stack.Lifo()
array.Push(as.Bytes(12.34))
array.Push(as.Float(13.37))
array.Push(as.String(23.0))
for array.Len() > 0 {
log.Println(array.Pop())
}
##xmath
import "simonwaldherr.de/go/golibs/xmath"
xmath provides a few mathematical functions like Max, Min, Sum, Median, Harmonic-mean, ...
var f = []float64{.5, 1.33, 2.66, 3.99, 13.37, 23.42, 42.000003}
fmt.Printf("Max: %v\n", xmath.Max(f))
fmt.Printf("Min: %v\n", xmath.Min(f))
fmt.Printf("Sum: %v\n", xmath.Sum(f))
fmt.Printf("Median: %v\n", xmath.Median(f))
fmt.Printf("Arithmetic: %v\n", xmath.Arithmetic(f))
fmt.Printf("Harmonic: %v\n", xmath.Harmonic(f))
fmt.Printf("Geometric: %v\n", xmath.Geometric(f))