Add examples to readme
This commit is contained in:
parent
df01f2eed7
commit
0df8b1ec84
33
README.md
33
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
|
||||
})
|
||||
```
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue