{"id":22785897,"url":"https://github.com/simonwaldherr/golibs","last_synced_at":"2025-05-07T15:23:28.463Z","repository":{"id":14844321,"uuid":"17567331","full_name":"SimonWaldherr/golibs","owner":"SimonWaldherr","description":"general purpose Golang code (to be included in other projects)","archived":false,"fork":false,"pushed_at":"2024-07-23T19:26:49.000Z","size":2470,"stargazers_count":121,"open_issues_count":2,"forks_count":17,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-12T16:25:49.222Z","etag":null,"topics":["examples","go","golang","hacktoberfest-accepted","libraries","package"],"latest_commit_sha":null,"homepage":"https://simonwaldherr.github.io/golibs/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SimonWaldherr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"simonwaldherr","patreon":"simonwaldherr","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"SimonWaldherr","issuehunt":null,"otechie":null,"custom":["https://flattr.com/@SimonWaldherr"]}},"created_at":"2014-03-09T15:36:49.000Z","updated_at":"2024-12-17T08:30:52.000Z","dependencies_parsed_at":"2022-08-31T00:20:48.943Z","dependency_job_id":"5a173459-b360-43a3-a715-ccd5a311e393","html_url":"https://github.com/SimonWaldherr/golibs","commit_stats":{"total_commits":224,"total_committers":3,"mean_commits":74.66666666666667,"dds":0.008928571428571397,"last_synced_commit":"2bc17abba126b8915abc797a7116c858e32027e8"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonWaldherr%2Fgolibs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonWaldherr%2Fgolibs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonWaldherr%2Fgolibs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonWaldherr%2Fgolibs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SimonWaldherr","download_url":"https://codeload.github.com/SimonWaldherr/golibs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252903280,"owners_count":21822414,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["examples","go","golang","hacktoberfest-accepted","libraries","package"],"created_at":"2024-12-11T23:08:22.651Z","updated_at":"2025-05-07T15:23:28.424Z","avatar_url":"https://github.com/SimonWaldherr.png","language":"Go","funding_links":["https://github.com/sponsors/simonwaldherr","https://patreon.com/simonwaldherr","https://liberapay.com/SimonWaldherr","https://flattr.com/@SimonWaldherr"],"categories":[],"sub_categories":[],"readme":"# golibs\n\n\ngolang functions (to be included in other projects)\n\n```sh\ngo get -u -t simonwaldherr.de/go/golibs/...\n```\n\n## coverage \u0026 tests\n\n```sh\ngo test ./...\n```\n\n\n . | service | info\n---|---------|------\n [![Audit](https://github.com/SimonWaldherr/golibs/actions/workflows/audit.yml/badge.svg?branch=master\u0026event=push)](https://github.com/SimonWaldherr/golibs/actions/workflows/audit.yml) | github.com  | test via GitHub Workflow  \n [![Go Report Card](https://goreportcard.com/badge/simonwaldherr.de/go/golibs)](https://goreportcard.com/report/simonwaldherr.de/go/golibs) | goreportcard.com | report card  \n [![Coverage Status](https://img.shields.io/coveralls/SimonWaldherr/golibs.svg?style=flat-square)](https://simonwaldherr.github.io/golibs/coverage/coverage.html) |  | go tool cover  \n [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FSimonWaldherr%2Fgolibs.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2FSimonWaldherr%2Fgolibs?ref=badge_shield) | fossa.io | license report  \n [![License MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/SimonWaldherr/golibs/master/LICENSE) |  | free + open source license  \n [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://pkg.go.dev/simonwaldherr.de/go/golibs) | godoc.org | documentation  \n [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://simonwaldherr.github.io/golibs/godoc/pkg/simonwaldherr.de/go/golibs.html) | godoc @ github.io | documentation  \n [![DOI](https://zenodo.org/badge/17567331.svg)](https://zenodo.org/badge/latestdoi/17567331) | zenodo.org | Digital Object Identifier\n\n\neach new build gets tested in multiple steps:\n\n* on development i regularly type ```go test``` from time to time to check the test suite\n* also there are a few go apps in the [examples](https://github.com/SimonWaldherr/golibs/tree/master/examples)-folder which i test to build and run\n* on commit, git automatically runs the [pre-commit](https://github.com/SimonWaldherr/golibs/blob/master/pre-commit)-hook shell script\n* after a commit gets pushed to **GitHub**, the following tests are started via Webhooks and Services\n\t* **Travis CI** build the lib and all tests on docker containers with the go versions noted in [.travis.yml](https://github.com/SimonWaldherr/golibs/blob/master/.travis.yml)\n\t* **semaphoreci**, yet another (linux (ubuntu) based) ci service\n\n\n## ToC\n\n* [ansi](https://github.com/SimonWaldherr/golibs#ansi-----) can print colored and styled text to your terminal\n* [arg](https://github.com/SimonWaldherr/golibs#arg-----) simplifies cli flags (arguments)\n* [as](https://github.com/SimonWaldherr/golibs#as-----) can convert most standard data types to most other data types\n* [bitmask](https://github.com/SimonWaldherr/golibs#bitmask-----) set and get bits in a bitmask\n* [cache](https://github.com/SimonWaldherr/golibs#cache-----) is an easy and small caching package\n* [cachedfile](https://github.com/SimonWaldherr/golibs#cachedfile-----) simplifies reading and writing from and to disk and adds caching\n* [channel](https://github.com/SimonWaldherr/golibs#channel-----) simplifies channel operations, e.g. sending the same data to multiple receivers\n* [csv](https://github.com/SimonWaldherr/golibs#csv-----) load and parse CSV file\n* [file](https://github.com/SimonWaldherr/golibs#file-----) wraps around the standard functions to simplify reading and writing on disk\n* [foreach](https://github.com/SimonWaldherr/golibs#foreach-----) calls a given function for each element of a [ JSON-string ]\n* [gcurses](https://github.com/SimonWaldherr/golibs#gcurses-----) enabling the development of text user interface applications\n* [gopath](https://github.com/SimonWaldherr/golibs#gopath-----) provides an easy way to get system information\n* [graphics](https://github.com/SimonWaldherr/golibs#graphics-----) can manipulate images\n* [http](https://github.com/SimonWaldherr/golibs#http-----) make easy and fast HTTP(S) requests\n* [log](https://github.com/SimonWaldherr/golibs#log-----) helps on logging your applications status\n* [re](https://github.com/SimonWaldherr/golibs#re-----) helps you whenever you have to do something multiple times\n* [regex](https://github.com/SimonWaldherr/golibs#regex-----) is a layer to speed up your regular expression development\n* [rss](https://github.com/SimonWaldherr/golibs#rss-----) is a rss feed parser based on Golangs std xml package\n* [semver](https://github.com/SimonWaldherr/golibs#semver-----) is a semantic version parsing/checking package\n* [ssl](https://github.com/SimonWaldherr/golibs#ssl-----) generates ssl certificates for https\n* [stack](https://github.com/SimonWaldherr/golibs#stack-----) can store your values in stacks and rings\n* [structs](https://github.com/SimonWaldherr/golibs#structs-----) use structs like maps\n* [table](https://github.com/SimonWaldherr/golibs#table-----) prints structs like ASCII or Markdown tables\n* [xmath](https://github.com/SimonWaldherr/golibs#xmath-----) provides a few mathematical functions like Sum, Median, Harmonic-mean, …\n* [xtime](https://github.com/SimonWaldherr/golibs#xtime-----) xtime implements a subset of strftime\n\n## WARNING\n\nsome functions in this repo enables you to write really bad code - I wrote it anyway because:  \n\n* sometimes you need a quick and dirty solution\n* it shows you possible ways, feel free to fork and customize\n* mostly bad go code is better than good php code - every aspect in golang is designed to prevent from bad code\n\nBUT: please remember that you can do things more performantly e.g. converting a string to a float is much faster done with strconv.ParseFloat than with as.Float.  \n\n## sublibs\n\n### ansi - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/ansi) \n\n```go\nimport \"simonwaldherr.de/go/golibs/ansi\"\n```\n\n**ansi** can print colored and styled text to your terminal:\n\n* green, yellow and red strings:  \n\n```go\nlog.Println(ansi.Color(\"INFO: everything is fine\", ansi.Green))\nlog.Println(ansi.Color(\"WARNING: not everything is fine\", ansi.Yellow))\nlog.Println(ansi.Color(\"ERROR: OMG!!!\", ansi.Red))\n```\n\n* bold and underlined text:  \n\n```go\nfmt.Printf(\"this is %v and %v text\", ansi.Bold(\"bold\"), ansi.Underline(\"underlined\"))\n```\n\n### arg - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/arg) \n\n```go\nimport \"simonwaldherr.de/go/golibs/arg\"\n```\n\nthe **arg** package simplifies cli flags (arguments)\n\n### as - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/as) \n\n```go\nimport \"simonwaldherr.de/go/golibs/as\"\n```\n\nwith **as** you can convert most standard data types to most other data types e.g.\n\n* int to string:  \n\n```go\nvar x string = as.String(int(32))\n```\n\n* string to int:  \n\n```go\nvar x int = as.Int(\"32\")\n```\n\n* string to time:  \n\n```go\nvar x time.Time = as.Time(\"31.12.2014\")\n```\n\n### bitmask - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/bitmask) \n\n```go\nimport \"simonwaldherr.de/go/golibs/bitmask\"\n```\n\nwith **bitmask** you can set and get bits to and from a bitmask:  \n\n```go\ni := bitmask.New(0b11111111)\ni.Set(0, false)\n```\n\n### cache - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/cache) \n\n```go\nimport \"simonwaldherr.de/go/golibs/cache\"\n```\n\n### cachedfile - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/cachedfile) \n\n```go\nimport \"simonwaldherr.de/go/golibs/cachedfile\"\n```\n\n**cachedfile** simplifies reading and writing from and to disk and adds caching\n\ndo\n\n```go\nstr := \"Neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit.\"\nerr := cachedfile.Write(\"filename.txt\", str, false)\n```\n\nand in less then 15 minutes this\n\n```go\nstr, _ := cachedfile.Read(\"filename.txt\")\n```\n\nand there will be no file access to disk.\nIf you kill the App, wait 15 min or call ```cachedfile.Stop()``` the cached content will be exported to disk.\n\n### channel - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/channel) \n\n```go\nimport \"simonwaldherr.de/go/golibs/channel\"\n```\n\n**channel** simplifies channel operations, e.g. sending the same data to multiple receivers\n\n```go\ncon := channel.Init()\n\nreceiver01 := con.AddReceiver()\nreceiver02 := con.AddReceiver()\nreceiver03 := con.AddReceiver()\n\ngo func() {\n  fmt.Println(\u003c-receiver01)\n}()\n\ngo func() {\n  fmt.Println(\u003c-receiver02)\n}()\n\ngo func() {\n  fmt.Println(\u003c-receiver03)\n}()\n\ntransmitter01 := con.AddTransmitter()\n\ntransmitter01 \u003c- \"Hello World\"\n```\n\n### csv - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/csv) \n\n```go\nimport \"simonwaldherr.de/go/golibs/csv\"\n```\n\n### file - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/file) \n\n```go\nimport \"simonwaldherr.de/go/golibs/file\"\n```\n\n**file** wraps around the standard functions to simplify reading and writing on disk\n\n```go\nstr := \"Neque porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit.\"\nerr := file.Write(\"filename.txt\", str, false)\n```\n\nBesides simple reading and writing, the package also contains functions to test file statuses, read large files by small blocks, clear, rename and delete files.\nThere is even a function for do things with each file in a directory (even with subfolders):\n\n```go\nerr := file.Each(\"..\", true, func(filename, extension, filepath string, dir bool, fileinfo os.FileInfo) {\n\tif extension == \"go\" \u0026\u0026 !dir {\n\t\tt.Logf(\"%v, %v, %v, %v\\n\", filename, filepath, dir, fileinfo)\n\t}\n}\n```\n\nIf you need the absolute path to a file, but only have a relative path, you can use ```file.GetAbsolutePath(\"~/path/to/file.txt\")```.  \n\n### foreach - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/foreach) \n\n```go\nimport \"simonwaldherr.de/go/golibs/foreach\"\n```\n\n**foreach** calls a given function for each element of a [ JSON-string ]\n\n### gcurses - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/gcurses) \n\n```go\nimport \"simonwaldherr.de/go/golibs/gcurses\"\n```\n\n**gcurses** is a terminal control library for Unixoide systems, enabling the development of text user interface applications.  \n\nNamed after the \"GUI-like\" terminal application toolkit [ncurses](https://en.wikipedia.org/wiki/Ncurses) (new curses) which is named after the original [curses](https://en.wikipedia.org/wiki/Curses_(programming_library)). \nThis library is in a very early stage.  \n\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"simonwaldherr.de/go/golibs/gcurses\"\n  \"time\"\n)\n\nfunc main() {\n  writer := gcurses.New()\n\n  writer.Start()\n\n  for i := 0; i \u003c 100; i++ {\n    fmt.Fprintf(writer, \"Count till one hundred: %d\\nStill counting ...\\n\", i)\n    time.Sleep(time.Millisecond * 10)\n  }\n\n  time.Sleep(time.Millisecond * 500)\n  fmt.Fprintln(writer, \"Finished counting\")\n\n  writer.Stop()\n}\n```\n\n### gopath - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/gopath) \n\n```go\nimport \"simonwaldherr.de/go/golibs/gopath\"\n```\n\n**gopath** provides an easy way to get system information\n\nto read a config file in which is in the same file as the executable, you can do something like this:\n\n```go\npackage main\n\nimport (\n  \"fmt\"\n  \"path/filepath\"\n  \"simonwaldherr.de/go/golibs/file\"\n  \"simonwaldherr.de/go/golibs/gopath\"\n)\n\nfunc main() {\n  dir := gopath.Dir()\n  config := file.Read(filepath.Join(dir, \"config.yaml\"))\n  \n  ...\n```\n\n### graphics - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/graphics) \n\n```go\nimport \"simonwaldherr.de/go/golibs/graphics\"\n```\n\nwith **graphics** you can manipulate images  \n\n```go\nimg := graphics.EachPixel(file, func(r, g, b, a uint8) (uint8, uint8, uint8, uint8) {\n\treturn g, b, r, a\n})\n```\n\nyou even can apply filters to images:\n\n```go\nfile, _ := os.Open(\"./original.png\")\ndefer file.Close()\n\nimg, _, err := image.Decode(file)\n\nimg = Edgedetect(img)\n\nout, _ := os.Create(\"./edgeDetect.png\")\n\npng.Encode(out, img)\nfd.Close()\n\n```\n\n\n### http - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/http) \n\n```go\nimport \"simonwaldherr.de/go/golibs/http\"\n```\n\n### log - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/log) \n\n```go\nimport \"simonwaldherr.de/go/golibs/log\"\n```\n\n\n### re - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/re) \n\n```go\nimport \"simonwaldherr.de/go/golibs/re\"\n```\n\n**re** helps you whenever you have to do something multiple times  \n\n```go\ndata, stop := re.Do(time.Second * 5, func(data chan\u003c- interface{}) {\n\tdata \u003c- fmt.Sprintf(\"%v\\n\", time.Now().Format(\"02.01.2006 15:04:05\"))\n})\n```\n\n\n### regex - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/regex) \n\n```go\nimport \"simonwaldherr.de/go/golibs/regex\"\n```\n\n**regex** is a layer to speed up your regular expression development  \n\n```go\nstr, err := regex.ReplaceAllString(\"Ipsum Lorem\", \"([^ ]+) ([^ ]+)\", \"$2 $1\")\n```\n\n\n### rss - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/rss) \n\n```go\nimport \"simonwaldherr.de/go/golibs/rss\"\n```\n\n**rss** is a rss feed parser based on Golangs std xml package  \n\n```go\npodcast, err := rss.Read(url)\nif err == nil {\n  for _, episode := range podcast.Items {\n    fmt.Println(episode.Title)\n  }\n}\n```\n\n\n### ssl - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/ssl) \n\n```go\nimport \"simonwaldherr.de/go/golibs/ssl\"\n```\n\n**ssl** generates ssl certificates for http**s**  \n\n```go\nerr := ssl.Generate(options)\n```\n\n\n### stack - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/stack) \n\n```go\nimport \"simonwaldherr.de/go/golibs/stack\"\n```\n\nwith **stack** you can store your values in stacks and rings  \n\n```go\narray := stack.Lifo()\narray.Push(as.Bytes(12.34))\narray.Push(as.Float(13.37))\narray.Push(as.String(23.0))\nfor array.Len() \u003e 0 {\n\tlog.Println(array.Pop())\n}\n```\n\n### structs - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/structs) \n\n```go\nimport \"simonwaldherr.de/go/golibs/structs\"\n```\n\n### xmath - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/xmath) \n\n```go\nimport \"simonwaldherr.de/go/golibs/xmath\"\n```\n\n**xmath** provides a few mathematical functions like *Max*, *Min*, *Sum*, *Median*, *Harmonic*-mean, ...\n\n```go\nvar f = []float64{.5, 1.33, 2.66, 3.99, 13.37, 23.42, 42.000003}\n\nfmt.Printf(\"Max: %v\\n\", xmath.Max(f))\nfmt.Printf(\"Min: %v\\n\", xmath.Min(f))\nfmt.Printf(\"Sum: %v\\n\", xmath.Sum(f))\n\nfmt.Printf(\"Median:     %v\\n\", xmath.Median(f))\nfmt.Printf(\"Arithmetic: %v\\n\", xmath.Arithmetic(f))\nfmt.Printf(\"Harmonic:   %v\\n\", xmath.Harmonic(f))\nfmt.Printf(\"Geometric:  %v\\n\", xmath.Geometric(f))\n```\n\n### xtime - [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/SimonWaldherr/golibs/xtime) \n\n```go\nimport \"simonwaldherr.de/go/golibs/xtime\"\n```\n\n**xtime** implements a subset of [strftime](http://man7.org/linux/man-pages/man3/strftime.3.html)\n\n```go\nt, _ := time.Now()\nfmt.Println(xtime.Fmt(\"%Y-%m-%d %H:%M:%S\", t))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonwaldherr%2Fgolibs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonwaldherr%2Fgolibs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonwaldherr%2Fgolibs/lists"}