Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2024-12-07 02:35:30 +03:00
parent 8729d0b88e
commit c5f3fa325e
42 changed files with 1316 additions and 2009 deletions

View File

@@ -5,16 +5,17 @@ import (
"errors"
"time"
"git.unistack.org/unistack-org/pkgdash/internal/models"
pb "git.unistack.org/unistack-org/pkgdash/proto"
"github.com/jmoiron/sqlx"
"go.unistack.org/micro/v3/logger"
"go.unistack.org/pkgdash/internal/models"
pb "go.unistack.org/pkgdash/proto"
)
func RegisterStorage(name string, fn func(*sqlx.DB) interface{}) {
func RegisterStorage(name string, fn func(logger.Logger, *sqlx.DB) interface{}) {
storages[name] = fn
}
var storages = map[string]func(*sqlx.DB) interface{}{}
var storages = map[string]func(logger.Logger, *sqlx.DB) interface{}{}
type Storage interface {
PackageModulesCreate(ctx context.Context, pkg *models.Package, modules []*models.Module) error
@@ -35,12 +36,12 @@ type Storage interface {
ModuleCreate(ctx context.Context, modules []*models.Module) error
}
func NewStorage(name string, db *sqlx.DB) (Storage, error) {
function, ok := storages[name]
func NewStorage(name string, log logger.Logger, db *sqlx.DB) (Storage, error) {
fn, ok := storages[name]
if !ok {
return nil, errors.New("incorrect name store")
}
store := function(db)
store := fn(log, db)
database, ok := store.(Storage)
if !ok {
return nil, errors.New("dont implements interface Storage")