Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
0a966a637b
|
@@ -5,9 +5,13 @@ import (
|
|||||||
"gopkg.in/mgo.v2/bson"
|
"gopkg.in/mgo.v2/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Connection interface {
|
||||||
|
Close()
|
||||||
|
NewSession() Session
|
||||||
|
}
|
||||||
|
|
||||||
type Session interface {
|
type Session interface {
|
||||||
Close()
|
Close()
|
||||||
Copy() Session
|
|
||||||
DB(name string) Database
|
DB(name string) Database
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module gitbase.de/gopackage/mgoapi/v2
|
|||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitbase.de/gopackage/mgocrud/v2 v2.0.5
|
gitbase.de/gopackage/mgocrud/v2 v2.0.8
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
|
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,5 +1,5 @@
|
|||||||
gitbase.de/gopackage/mgocrud/v2 v2.0.5 h1:sgRJXw0ZvNDtsjmIhNDoe/8pO0Bed313aXFX6SlW6fQ=
|
gitbase.de/gopackage/mgocrud/v2 v2.0.8 h1:129q3/5c4kFB0WnVZZXd+jhpR5FYjYjzmcoZxLPPjiY=
|
||||||
gitbase.de/gopackage/mgocrud/v2 v2.0.5/go.mod h1:eAIqxjo60/nP/S+YA25SBLQZ98WUrHwpvjE7Zl+ewTM=
|
gitbase.de/gopackage/mgocrud/v2 v2.0.8/go.mod h1:eAIqxjo60/nP/S+YA25SBLQZ98WUrHwpvjE7Zl+ewTM=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
|||||||
10
handler.go
10
handler.go
@@ -15,7 +15,7 @@ import (
|
|||||||
func (api *API) collectionGetOneHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
func (api *API) collectionGetOneHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
|
||||||
session := api.DBSession.Copy()
|
session := api.DBConnection.NewSession()
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
db := session.DB(api.DBName)
|
db := session.DB(api.DBName)
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ func (api *API) collectionGetHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
|||||||
|
|
||||||
results := x.Interface()
|
results := x.Interface()
|
||||||
|
|
||||||
session := api.DBSession.Copy()
|
session := api.DBConnection.NewSession()
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
db := session.DB(api.DBName)
|
db := session.DB(api.DBName)
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ func (api *API) collectionPostHandler(m mgocrud.ModelInterface) gin.HandlerFunc
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
session := api.DBSession.Copy()
|
session := api.DBConnection.NewSession()
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
db := session.DB(api.DBName)
|
db := session.DB(api.DBName)
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ func (api *API) collectionPostHandler(m mgocrud.ModelInterface) gin.HandlerFunc
|
|||||||
|
|
||||||
func (api *API) collectionPutHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
func (api *API) collectionPutHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
session := api.DBSession.Copy()
|
session := api.DBConnection.NewSession()
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
db := session.DB(api.DBName)
|
db := session.DB(api.DBName)
|
||||||
|
|
||||||
@@ -399,7 +399,7 @@ func (api *API) collectionPutHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
|||||||
func (api *API) collectionDeleteHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
func (api *API) collectionDeleteHandler(m mgocrud.ModelInterface) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
|
||||||
session := api.DBSession.Copy()
|
session := api.DBConnection.NewSession()
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
db := session.DB(api.DBName)
|
db := session.DB(api.DBName)
|
||||||
|
|
||||||
|
|||||||
2
login.go
2
login.go
@@ -26,7 +26,7 @@ func (api *API) loginPostHandler(m LoginModel) func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
session := api.DBSession.Copy()
|
session := api.DBConnection.NewSession()
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
db := session.DB(api.DBName)
|
db := session.DB(api.DBName)
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
// API is wrapper for one RouterGroup and mgo DB
|
// API is wrapper for one RouterGroup and mgo DB
|
||||||
type API struct {
|
type API struct {
|
||||||
DBSession Session
|
DBConnection Connection
|
||||||
DBName string
|
DBName string
|
||||||
routerGroup *gin.RouterGroup
|
routerGroup *gin.RouterGroup
|
||||||
jwtSecret []byte
|
jwtSecret []byte
|
||||||
@@ -22,9 +22,9 @@ type Context struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New returns new instance of the API
|
// New returns new instance of the API
|
||||||
func New(session Session, dbname string, routerGroup *gin.RouterGroup) *API {
|
func New(connection Connection, dbname string, routerGroup *gin.RouterGroup) *API {
|
||||||
return &API{
|
return &API{
|
||||||
DBSession: session,
|
DBConnection: connection,
|
||||||
DBName: dbname,
|
DBName: dbname,
|
||||||
routerGroup: routerGroup,
|
routerGroup: routerGroup,
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ func (api *API) RegisterModel(m mgocrud.ModelInterface) {
|
|||||||
|
|
||||||
modelRegistry = append(modelRegistry, m)
|
modelRegistry = append(modelRegistry, m)
|
||||||
|
|
||||||
session := api.DBSession.Copy()
|
session := api.DBConnection.NewSession()
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
db := session.DB(api.DBName)
|
db := session.DB(api.DBName)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user