From 8ad4e706231dc12f533801969a3f96035f590c96 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Sun, 24 Jun 2018 03:06:28 +0200 Subject: [PATCH] Add set docs --- README.md | 33 +++++++++++++++++++++++++++++---- config/config.go | 1 + log/log.go | 2 +- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 config/config.go diff --git a/README.md b/README.md index 01e72ad..ff9de76 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ import "github.com/localhots/gobelt/threadpool" ```go ctx := context.Background() -ctx, cancel = context.WithTimeout(ctx, 30 * time.Second) +ctx, cancel = context.WithTimeout(ctx, 30*time.Second) defer cancel() pool := threadpool.New(10) @@ -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 }) @@ -60,4 +61,28 @@ 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 -``` \ No newline at end of file +``` + +### 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] +``` diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..d912156 --- /dev/null +++ b/config/config.go @@ -0,0 +1 @@ +package config diff --git a/log/log.go b/log/log.go index 7b8a807..4d65480 100644 --- a/log/log.go +++ b/log/log.go @@ -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)) }