Skip to content

Commit 87a3238

Browse files
committed
api/auth: fix invalid mgo session
This patch updates the outdated mgo package to the community version github.com/globalsign/mgo to fix the issue that the mgo session cannot be used after the primary node shutdown and re-elected. Related issue: globalsign/mgo#5
1 parent c4a6a93 commit 87a3238

File tree

8 files changed

+84
-34
lines changed

8 files changed

+84
-34
lines changed

controllers/controller-factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66

77
"github.com/twreporter/go-api/internal/news"
88

9+
"github.com/globalsign/mgo"
910
"github.com/jinzhu/gorm"
1011
"github.com/twreporter/go-api/globals"
1112
"github.com/twreporter/go-api/services"
1213
"github.com/twreporter/go-api/storage"
1314
"github.com/twreporter/go-api/utils"
1415
"go.mongodb.org/mongo-driver/mongo"
15-
"gopkg.in/mgo.v2"
1616
)
1717

1818
// ControllerFactory generates controlloers by given persistent storage connection

go.mod

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.12
44

55
require (
66
cloud.google.com/go v0.52.0 // indirect
7-
github.com/algolia/algoliasearch-client-go v2.25.0+incompatible
87
github.com/algolia/algoliasearch-client-go/v3 v3.16.0
98
github.com/auth0/go-jwt-middleware v0.0.0-20170425171159-5493cabe49f7
109
github.com/aws/aws-sdk-go v1.34.28
@@ -13,45 +12,48 @@ require (
1312
github.com/dgrijalva/jwt-go v3.2.0+incompatible
1413
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 // indirect
1514
github.com/gin-contrib/cors v0.0.0-20170708080947-567de1916927
16-
github.com/gin-contrib/sessions v0.0.0-20180827025425-58cbcf30135c
17-
github.com/gin-gonic/gin v1.5.0
18-
github.com/go-playground/universal-translator v0.17.0 // indirect
15+
github.com/gin-contrib/sessions v0.0.3
16+
github.com/gin-gonic/gin v1.6.3
17+
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
18+
github.com/go-playground/validator/v10 v10.7.0 // indirect
1919
github.com/go-sql-driver/mysql v1.5.0
2020
github.com/gofrs/uuid v3.2.0+incompatible // indirect
2121
github.com/golang-migrate/migrate/v4 v4.6.1
22+
github.com/golang/protobuf v1.5.2 // indirect
2223
github.com/google/uuid v1.1.1
2324
github.com/gorilla/mux v1.7.2 // indirect
24-
github.com/gorilla/sessions v1.1.1 // indirect
25+
github.com/gorilla/sessions v1.2.1 // indirect
2526
github.com/jinzhu/copier v0.0.0-20180308034124-7e38e58719c3
2627
github.com/jinzhu/gorm v1.9.2
2728
github.com/jinzhu/inflection v0.0.0-20170102125226-1c35d901db3d // indirect
2829
github.com/jinzhu/now v1.0.1 // indirect
29-
github.com/json-iterator/go v1.1.9 // indirect
30-
github.com/kidstuff/mongostore v0.0.0-20180412085134-db2a8b4fac1f // indirect
30+
github.com/json-iterator/go v1.1.11 // indirect
3131
github.com/kr/pretty v0.2.0 // indirect
32-
github.com/leodido/go-urn v1.2.0 // indirect
32+
github.com/leodido/go-urn v1.2.1 // indirect
3333
github.com/lib/pq v1.1.1 // indirect
3434
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2 // indirect
35-
github.com/mattn/go-isatty v0.0.12 // indirect
35+
github.com/mattn/go-isatty v0.0.13 // indirect
3636
github.com/pkg/errors v0.9.1
3737
github.com/sirupsen/logrus v1.4.2
3838
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a // indirect
3939
github.com/spf13/viper v1.3.2
4040
github.com/stretchr/testify v1.6.1
4141
github.com/twreporter/logformatter v0.0.0-20200211094126-60fe42618206
42+
github.com/ugorji/go v1.2.6 // indirect
4243
go.mongodb.org/mongo-driver v1.4.6
43-
golang.org/x/crypto v0.0.0-20200210222208-86ce3cb69678
44+
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
4445
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
45-
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 // indirect
46+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
47+
golang.org/x/text v0.3.6 // indirect
4648
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
4749
google.golang.org/genproto v0.0.0-20200211035748-55294c81d784 // indirect
4850
google.golang.org/grpc v1.27.1 // indirect
51+
google.golang.org/protobuf v1.27.1 // indirect
4952
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
5053
gopkg.in/go-playground/validator.v8 v8.18.2
51-
gopkg.in/go-playground/validator.v9 v9.31.0 // indirect
5254
gopkg.in/guregu/null.v3 v3.4.0
5355
gopkg.in/matryer/try.v1 v1.0.0-20150601225556-312d2599e12e
54-
gopkg.in/mgo.v2 v2.0.0-20160818020120-3f83fa500528
56+
gopkg.in/yaml.v2 v2.4.0 // indirect
5557
)
5658

5759
replace (

go.sum

Lines changed: 62 additions & 14 deletions
Large diffs are not rendered by default.

storage/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package storage
22

33
import (
4+
"github.com/globalsign/mgo"
45
"github.com/go-sql-driver/mysql"
56
"github.com/jinzhu/gorm"
67
"github.com/pkg/errors"
7-
"gopkg.in/mgo.v2"
88
)
99

1010
// ErrRecordNotFound record not found error, happens when haven't find any matched data when looking up with a struct

tests/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/algolia/algoliasearch-client-go/v3/algolia/search"
1616

1717
"github.com/gin-gonic/gin"
18+
"github.com/globalsign/mgo"
1819
"github.com/jinzhu/gorm"
1920
"github.com/stretchr/testify/assert"
2021
"github.com/twreporter/go-api/configs"
@@ -25,7 +26,6 @@ import (
2526
"github.com/twreporter/go-api/storage"
2627
"github.com/twreporter/go-api/utils"
2728
mongodriver "go.mongodb.org/mongo-driver/mongo"
28-
"gopkg.in/mgo.v2"
2929
)
3030

3131
var Globs globalVariables

tests/pre_test_environment_setup.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88

99
"go.mongodb.org/mongo-driver/mongo/options"
1010

11+
"github.com/globalsign/mgo"
12+
"github.com/globalsign/mgo/bson"
1113
"github.com/jinzhu/gorm"
1214
mongodriver "go.mongodb.org/mongo-driver/mongo"
13-
"gopkg.in/mgo.v2"
14-
"gopkg.in/mgo.v2/bson"
1515

1616
"github.com/twreporter/go-api/globals"
1717
"github.com/twreporter/go-api/internal/mongo"

tests/structs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package tests
22

33
import (
44
"github.com/gin-gonic/gin"
5+
"github.com/globalsign/mgo"
56
"github.com/jinzhu/gorm"
6-
"gopkg.in/mgo.v2"
77
)
88

99
type defaultVariables struct {

utils/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
"time"
99

10+
"github.com/globalsign/mgo"
1011
"github.com/golang-migrate/migrate/v4"
1112
"github.com/golang-migrate/migrate/v4/database/mysql"
1213
_ "github.com/golang-migrate/migrate/v4/source/file"
@@ -17,7 +18,6 @@ import (
1718
"go.mongodb.org/mongo-driver/mongo/options"
1819
"go.mongodb.org/mongo-driver/mongo/readpref"
1920
"gopkg.in/matryer/try.v1"
20-
"gopkg.in/mgo.v2"
2121

2222
"github.com/twreporter/go-api/globals"
2323
"github.com/twreporter/go-api/models"

0 commit comments

Comments
 (0)