Add set docs
This commit is contained in:
parent
01c445213c
commit
8ad4e70623
33
README.md
33
README.md
|
@ -10,7 +10,7 @@ import "github.com/localhots/gobelt/threadpool"
|
||||||
|
|
||||||
```go
|
```go
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx, cancel = context.WithTimeout(ctx, 30 * time.Second)
|
ctx, cancel = context.WithTimeout(ctx, 30*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
pool := threadpool.New(10)
|
pool := threadpool.New(10)
|
||||||
|
@ -30,12 +30,13 @@ import "github.com/localhots/gobelt/filecache"
|
||||||
```
|
```
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
ctx := context.Background()
|
||||||
var val int
|
var val int
|
||||||
filecache.Load(&val, "path/to/cachefile", func() interface{} {
|
filecache.Load(&val, "tmp/cache/items.json", func() interface{} {
|
||||||
var items []Item
|
var items []Item
|
||||||
err := conn.Query(ctx, "SELECT * FROM items").Load(&items).Error()
|
err := conn.Query(ctx, "SELECT * FROM items").Load(&items).Error()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Failed to load items", log.F{"error": err})
|
log.Fatalf("Failed to load items: %v", err)
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
})
|
})
|
||||||
|
@ -60,4 +61,28 @@ if err != nil {
|
||||||
|
|
||||||
log.Info(ctx, "New user signed up", log.F{"id": user.ID})
|
log.Info(ctx, "New user signed up", log.F{"id": user.ID})
|
||||||
// [INFO] New user signed up email=bob@example.com id=14
|
// [INFO] New user signed up email=bob@example.com id=14
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Set
|
||||||
|
|
||||||
|
There is a collection of packages implementing a set data type located inside
|
||||||
|
the `set` package. Implemented types include:
|
||||||
|
|
||||||
|
* `int`, `int8`, `int16`, `int32`, `int64`
|
||||||
|
* `uint`, `uint8`, `uint16`, `uint32`, `uint64`
|
||||||
|
* `string`
|
||||||
|
|
||||||
|
All the package names are type names prefixed with "set", e.g. `setuint64`.
|
||||||
|
|
||||||
|
```go
|
||||||
|
import "github.com/localhots/gobelt/set/setstring"
|
||||||
|
```
|
||||||
|
|
||||||
|
```go
|
||||||
|
s := setstring.New("one", "two")
|
||||||
|
s.Add("three")
|
||||||
|
s.Remove("one", "two").Add("four", "five")
|
||||||
|
fmt.Println("Size:", s.Len()) // 3
|
||||||
|
fmt.Println("Has one", s.Has("one"))
|
||||||
|
fmt.Println(s.SortedSlice()) // [three four five]
|
||||||
|
```
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
package config
|
|
@ -73,5 +73,5 @@ func withFields(f F) *logrus.Entry {
|
||||||
if len(f) == 0 {
|
if len(f) == 0 {
|
||||||
return logrus.NewEntry(Logger)
|
return logrus.NewEntry(Logger)
|
||||||
}
|
}
|
||||||
return logrus.WithFields(logrus.Fields(f))
|
return Logger.WithFields(logrus.Fields(f))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue