https://github.com/abiosoft/goutils
A set of utilities for Go
https://github.com/abiosoft/goutils
Last synced: 12 months ago
JSON representation
A set of utilities for Go
- Host: GitHub
- URL: https://github.com/abiosoft/goutils
- Owner: abiosoft
- License: mit
- Created: 2015-06-08T00:39:40.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-03-02T19:36:39.000Z (over 10 years ago)
- Last Synced: 2025-01-23T14:49:53.659Z (over 1 year ago)
- Language: Go
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goutils
A set of personal utilities for Go.
[](https://godoc.org/github.com/abiosoft/goutils)
[](https://drone.io/github.com/abiosoft/goutils/latest)
[](https://coveralls.io/r/abiosoft/goutils)
I will keep adding more packages as time goes on and the need arises.
### Packages
#### 1. Set
[](https://godoc.org/github.com/abiosoft/goutils/set)
##### Example
```go
import "github.com/abiosoft/goutils/set"
s := set.New()
// stores distinctly, repetitions have no effect.
s.AddAll(1, 1, 2, 2, 3, 6, 2, 1, "a", "b", "a")
s.Size() // 6
list := []interface{}{1, 2, 3, 6, "a", "b"}
s.ContainsList(list) // true
iter := s.Iterator()
for iter.HasNext() {
// do something with iter.Value()
...
}
```
#### 2. Environment Variables
[](https://godoc.org/github.com/abiosoft/goutils/env)
##### Example
```go
import "github.com/abiosoft/goutils/env"
var vars env.EnvVar
// set key and val
vars.Set("GOPATH", "$HOME/go")
// or set as a full string
vars.SetStr("GOPATH=$HOME/go")
// get
vars.Get("GOPATH") // $HOME/go
vars.Set("GOOS", "darwin")
vars.Get("GOOS") // darwin
vars.String() // GOPATH=$HOME/go\nGOOS=darwin
// though env.EnvVar is a slice, adding an invalid string has no effect.
vars = append(vars, "SOME STRING")
vars.SetStr("SOME STRING")
vars.String() // GOPATH=$HOME/go\nGOOS=darwin
```