Add set docs
This commit is contained in:
parent
01c445213c
commit
8ad4e70623
29
README.md
29
README.md
|
@ -30,12 +30,13 @@ import "github.com/localhots/gobelt/filecache"
|
|||
```
|
||||
|
||||
```go
|
||||
ctx := context.Background()
|
||||
var val int
|
||||
filecache.Load(&val, "path/to/cachefile", func() interface{} {
|
||||
filecache.Load(&val, "tmp/cache/items.json", func() interface{} {
|
||||
var items []Item
|
||||
err := conn.Query(ctx, "SELECT * FROM items").Load(&items).Error()
|
||||
if err != nil {
|
||||
log.Fatal("Failed to load items", log.F{"error": err})
|
||||
log.Fatalf("Failed to load items: %v", err)
|
||||
}
|
||||
return items
|
||||
})
|
||||
|
@ -61,3 +62,27 @@ if err != nil {
|
|||
log.Info(ctx, "New user signed up", log.F{"id": user.ID})
|
||||
// [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 {
|
||||
return logrus.NewEntry(Logger)
|
||||
}
|
||||
return logrus.WithFields(logrus.Fields(f))
|
||||
return Logger.WithFields(logrus.Fields(f))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue