db interface

This commit is contained in:
2022-02-09 20:21:08 +01:00
parent 2b4f13f807
commit d116f5d938
8 changed files with 82 additions and 18 deletions

View File

@@ -7,7 +7,7 @@ import (
// API is wrapper for one RouterGroup and mgo DB
type API struct {
DBSession *mgocrud.Session
DBSession Session
DBName string
routerGroup *gin.RouterGroup
jwtSecret []byte
@@ -18,11 +18,11 @@ type API struct {
type Context struct {
*gin.Context
API *API
DB *mgocrud.Database
DB Database
}
// New returns new instance of the API
func New(session *mgocrud.Session, dbname string, routerGroup *gin.RouterGroup) *API {
func New(session Session, dbname string, routerGroup *gin.RouterGroup) *API {
return &API{
DBSession: session,
DBName: dbname,
@@ -41,7 +41,7 @@ func (api *API) RegisterModel(m mgocrud.ModelInterface) {
defer session.Close()
db := session.DB(api.DBName)
err := mgocrud.EnsureIndex(db, m)
err := db.EnsureIndex(m)
if err != nil {
panic(err)
}