DataLoader
This is an implementation of Facebook's DataLoader in Golang.
Install
go get -u github.com/graph-gophers/dataloader
Usage
batchFn := func(ctx context.Context, keys dataloader.Keys) []*dataloader.Result {
var results []*dataloader.Result
return results
}
loader := dataloader.NewBatchedLoader(batchFn)
thunk := loader.Load(context.TODO(), dataloader.StringKey("key1"))
result, err := thunk()
if err != nil {
}
log.Printf("value: %#v", result)
Don't need/want to use context?
You're welcome to install the v1 version of this library.
Cache
This implementation contains a very basic cache that is intended only to be used for short lived DataLoaders (i.e. DataLoaders that only exist for the life of an http request). You may use your own implementation if you want.
it also has a NoCache
type that implements the cache interface but all methods are noop. If you do not wish to cache anything.
Examples
There are a few basic examples in the example folder.