From 0df8b1ec846de30a7c7b892b01eb229fb5146db6 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Sun, 17 Jun 2018 13:56:44 +0200 Subject: [PATCH] Add examples to readme --- README.md | 33 ++++++++++++++++++++++++++++++++- filecache/filecache_test.go | 1 - 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ec638bb..4dd67e4 100644 --- a/README.md +++ b/README.md @@ -1 +1,32 @@ -# Go tool belt +# Gobelt + +Gobelt is a collection of Go tools. + +### Thread pool + +```go +import "github.com/localhots/gobelt/threadpool" +``` + +```go +ctx := context.Background() +pool := threadpool.New(5) +pool.Enqueue(ctx, func() { + fmt.Println("Hello") +}) +pool.Close() +``` + +### File cache + +```go +import "github.com/localhots/gobelt/filecache" +``` + +```go +var val int +filecache.Load(&val, "path/to/cachefile", func() interface{} { + // Expensive calls here + return 100 +}) +``` diff --git a/filecache/filecache_test.go b/filecache/filecache_test.go index 29eaeeb..5d47b82 100644 --- a/filecache/filecache_test.go +++ b/filecache/filecache_test.go @@ -19,7 +19,6 @@ func TestFileCache(t *testing.T) { if err != nil { t.Fatalf("Error occurred while loading cache: %v", err) } - if res != exp { t.Errorf("Expected %d, got %d", exp, res) }