Skip to content

Latest commit

 

History

History
executable file
·
206 lines (138 loc) · 5.69 KB

README.md

File metadata and controls

executable file
·
206 lines (138 loc) · 5.69 KB

#golibs

golang functions (to be included in other projects)

go get -u -t simonwaldherr.de/go/golibs/...

go test ./...

| service | info ---|---------|------ Coverage Status | coveralls.io | test coverage
Build Status | travis-ci.org | test on various go versions
Build status | appveyor.com | test under windows
Build status | magnum-ci.com | yet another ci service
License MIT | | free + open source license
Flattr donate button | flattr.com | micro donation
GoDoc | godoc.org | documentation

##ansi

GoDoc

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

GoDoc

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

GoDoc

import "simonwaldherr.de/go/golibs/cache"

##file

GoDoc

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

GoDoc

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

GoDoc

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

GoDoc

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

GoDoc

import "simonwaldherr.de/go/golibs/ssl"

ssl generates ssl certificates for https

err := ssl.Generate(options)

##stack

GoDoc

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

GoDoc

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))