Skip to content

Commit c87fdce

Browse files
authored
Merge pull request #67 from graph-gophers/use-modules
Migrate from dep to modules
2 parents 07f793f + 07618e2 commit c87fdce

13 files changed

+68
-178
lines changed

.travis.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
language: go
22

33
go:
4-
- 1.8
5-
- 1.x
4+
- 1.15
5+
- 1.14
66

77
install:
8-
- go get -u github.com/golang/dep/...
9-
- dep ensure
8+
- go mod install
109

1110
script:
1211
- go test -v -race -coverprofile=coverage.txt -covermode=atomic

Godeps/Godeps.json

-21
This file was deleted.

Godeps/Readme

-5
This file was deleted.

Gopkg.lock

-33
This file was deleted.

Gopkg.toml

-34
This file was deleted.

MIGRATE.md

+11
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,14 @@ type Cache interface {
8686
Clear()
8787
}
8888
```
89+
90+
## Upgrade from v5 to v6
91+
92+
We add major version release because we switched to using Go Modules from dep,
93+
and drop build tags for older versions of Go (1.9).
94+
95+
The preferred import method includes the major version tag.
96+
97+
```go
98+
import "github.com/graph-gophers/dataloader/v6"
99+
```
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
package lru_cache_test
2+
13
// This is an exmaple of using go-cache as a long term cache solution for
24
// dataloader.
3-
package main
45

56
import (
67
"context"
78
"fmt"
89

10+
dataloader "github.com/graph-gophers/dataloader/v6"
911
lru "github.com/hashicorp/golang-lru"
10-
"github.com/nicksrandall/dataloader"
1112
)
1213

1314
// Cache implements the dataloader.Cache interface
14-
type Cache struct {
15+
type cache struct {
1516
*lru.ARCCache
1617
}
1718

1819
// Get gets an item from the cache
19-
func (c *Cache) Get(_ context.Context, key dataloader.Key) (dataloader.Thunk, bool) {
20+
func (c *cache) Get(_ context.Context, key dataloader.Key) (dataloader.Thunk, bool) {
2021
v, ok := c.ARCCache.Get(key)
2122
if ok {
2223
return v.(dataloader.Thunk), ok
@@ -25,12 +26,12 @@ func (c *Cache) Get(_ context.Context, key dataloader.Key) (dataloader.Thunk, bo
2526
}
2627

2728
// Set sets an item in the cache
28-
func (c *Cache) Set(_ context.Context, key dataloader.Key, value dataloader.Thunk) {
29+
func (c *cache) Set(_ context.Context, key dataloader.Key, value dataloader.Thunk) {
2930
c.ARCCache.Add(key, value)
3031
}
3132

3233
// Delete deletes an item in the cache
33-
func (c *Cache) Delete(_ context.Context, key dataloader.Key) bool {
34+
func (c *cache) Delete(_ context.Context, key dataloader.Key) bool {
3435
if c.ARCCache.Contains(key) {
3536
c.ARCCache.Remove(key)
3637
return true
@@ -39,14 +40,14 @@ func (c *Cache) Delete(_ context.Context, key dataloader.Key) bool {
3940
}
4041

4142
// Clear cleasrs the cache
42-
func (c *Cache) Clear() {
43+
func (c *cache) Clear() {
4344
c.ARCCache.Purge()
4445
}
4546

46-
func main() {
47-
// go-cache will automaticlly cleanup expired items on given diration
47+
func ExampleGolangLRU() {
48+
// go-cache will automaticlly cleanup expired items on given duration.
4849
c, _ := lru.NewARC(100)
49-
cache := &Cache{c}
50+
cache := &cache{ARCCache: c}
5051
loader := dataloader.NewBatchedLoader(batchFunc, dataloader.WithCache(cache))
5152

5253
// immediately call the future function from loader
@@ -55,14 +56,15 @@ func main() {
5556
// handle error
5657
}
5758

58-
fmt.Printf("identity: %s\n", result)
59+
fmt.Printf("identity: %s", result)
60+
// Output: identity: some key
5961
}
6062

6163
func batchFunc(_ context.Context, keys dataloader.Keys) []*dataloader.Result {
6264
var results []*dataloader.Result
6365
// do some pretend work to resolve keys
6466
for _, key := range keys {
65-
results = append(results, &dataloader.Result{key.String(), nil})
67+
results = append(results, &dataloader.Result{Data: key.String()})
6668
}
6769
return results
6870
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
package main
1+
package no_cache_test
22

33
import (
44
"context"
55
"fmt"
66

7-
"github.com/graph-gophers/dataloader"
7+
dataloader "github.com/graph-gophers/dataloader/v6"
88
)
99

10-
func main() {
10+
func ExampleNoCache() {
1111
// go-cache will automaticlly cleanup expired items on given diration
1212
cache := &dataloader.NoCache{}
1313
loader := dataloader.NewBatchedLoader(batchFunc, dataloader.WithCache(cache))
@@ -17,14 +17,15 @@ func main() {
1717
// handle error
1818
}
1919

20-
fmt.Printf("identity: %s\n", result)
20+
fmt.Printf("identity: %s", result)
21+
// Output: identity: some key
2122
}
2223

2324
func batchFunc(_ context.Context, keys dataloader.Keys) []*dataloader.Result {
2425
var results []*dataloader.Result
2526
// do some pretend work to resolve keys
2627
for _, key := range keys {
27-
results = append(results, &dataloader.Result{key.String(), nil})
28+
results = append(results, &dataloader.Result{Data: key.String()})
2829
}
2930
return results
3031
}

example/ttl-cache/go-cache.go renamed to example/ttl_cache/go_cache_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// This is an exmaple of using go-cache as a long term cache solution for
22
// dataloader.
3-
package main
3+
package ttl_cache_test
44

55
import (
66
"context"
77
"fmt"
88
"time"
99

10-
"github.com/nicksrandall/dataloader"
10+
dataloader "github.com/graph-gophers/dataloader/v6"
1111
cache "github.com/patrickmn/go-cache"
1212
)
1313

@@ -44,7 +44,7 @@ func (c *Cache) Clear() {
4444
c.c.Flush()
4545
}
4646

47-
func main() {
47+
func ExampleTTLCache() {
4848
// go-cache will automaticlly cleanup expired items on given diration
4949
c := cache.New(15*time.Minute, 15*time.Minute)
5050
cache := &Cache{c}
@@ -56,14 +56,15 @@ func main() {
5656
// handle error
5757
}
5858

59-
fmt.Printf("identity: %s\n", result)
59+
fmt.Printf("identity: %s", result)
60+
// Output: identity: some key
6061
}
6162

6263
func batchFunc(_ context.Context, keys dataloader.Keys) []*dataloader.Result {
6364
var results []*dataloader.Result
6465
// do some pretend work to resolve keys
6566
for _, key := range keys {
66-
results = append(results, &dataloader.Result{key.String(), nil})
67+
results = append(results, &dataloader.Result{Data: key.String()})
6768
}
6869
return results
6970
}

go.mod

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/graph-gophers/dataloader/v6
2+
3+
go 1.15
4+
5+
require (
6+
github.com/hashicorp/golang-lru v0.5.4
7+
github.com/opentracing/opentracing-go v1.2.0
8+
github.com/patrickmn/go-cache v2.1.0+incompatible
9+
github.com/stretchr/testify v1.6.1 // indirect
10+
)

go.sum

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
4+
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
5+
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
6+
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
7+
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
8+
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
9+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
10+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
11+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
12+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
13+
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
14+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
15+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
16+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
17+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
18+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

inMemoryCache_go19.go

-57
This file was deleted.

inMemoryCache.go renamed to in_memory_cache.go

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// +build !go1.9
2-
31
package dataloader
42

53
import (

0 commit comments

Comments
 (0)