Skip to content

Commit

Permalink
Merge pull request #21 from faabiosr/remove/mgo-driver
Browse files Browse the repository at this point in the history
remove: deprecate mongo mgo driver
  • Loading branch information
faabiosr authored Mar 18, 2023
2 parents b93d32a + 6b59b5c commit 93c7fa1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 172 deletions.
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/mattn/go-sqlite3 v1.14.16
go.etcd.io/bbolt v1.3.7
go.mongodb.org/mongo-driver v1.11.2
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
)

require (
Expand All @@ -18,7 +17,6 @@ require (
github.com/google/go-cmp v0.5.5 // indirect
github.com/klauspost/compress v1.13.6 // indirect
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
Expand All @@ -29,5 +27,4 @@ require (
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
)
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwp
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down Expand Up @@ -151,11 +149,7 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 h1:VpOs+IwYnYBaFnrNAeB8UUWtL3vEUnzSCL1nVjPhqrw=
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
11 changes: 7 additions & 4 deletions mongo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ The drivers uses [go-mgo](https://github.com/go-mgo/mgo) to store the cache data
package main

import (
"context"
"log"
"time"

"gopkg.in/mgo.v2"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"

"github.com/faabiosr/cachego/mongo"
)

func main() {
session, _ := mgo.Dial("localhost:27017")
opts := options.Client().ApplyURI("mongodb://localhost:27017")
client, _ := mongo.Connect(context.Background(), opts)

cache := mongo.New(
session.DB("cache").C("cache"),
)
client.Database("cache").Collection("cache"),
)

if err := cache.Save("user_id", "1", 10*time.Second); err != nil {
log.Fatal(err)
Expand Down
93 changes: 0 additions & 93 deletions mongo/mgo.go

This file was deleted.

63 changes: 0 additions & 63 deletions mongo/mgo_test.go

This file was deleted.

10 changes: 8 additions & 2 deletions mongo/mongo.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package mongo providers a cache driver that stores the cache in MongoDB.
package mongo

import (
Expand All @@ -23,11 +24,16 @@ type (
}
)

// NewMongoDriver creates an instance of Mongo cache driver
func NewMongoDriver(collection *mongo.Collection) cachego.Cache {
// New creates an instance of Mongo cache driver
func New(collection *mongo.Collection) cachego.Cache {
return &mongoCache{collection}
}

// NewMongoDriver alias for New.
func NewMongoDriver(collection *mongo.Collection) cachego.Cache {
return New(collection)
}

func (m *mongoCache) Contains(key string) bool {
_, err := m.Fetch(key)
return err == nil
Expand Down
2 changes: 1 addition & 1 deletion mongo/mongo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestMongo(t *testing.T) {
}
collection := client.Database("cache").Collection("cache")

cache := NewMongoDriver(collection)
cache := New(collection)

if err := cache.Save(testKeyMongo, testValueMongo, 1*time.Nanosecond); err != nil {
t.Errorf("save fail: expected nil, got %v", err)
Expand Down

0 comments on commit 93c7fa1

Please sign in to comment.