package storage import ( "context" "errors" "time" "git.unistack.org/unistack-org/pkgdash/internal/models" pb "git.unistack.org/unistack-org/pkgdash/proto" "github.com/jmoiron/sqlx" ) func RegisterStorage(name string, fn func(*sqlx.DB) interface{}) { storages[name] = fn } var storages = map[string]func(*sqlx.DB) interface{}{} type Storage interface { PackagesModulesCreate(ctx context.Context, pkg *models.Package, modules []*models.Module) error PackagesUpdateLastCheck(ctx context.Context, packages []*models.Package) error PackagesModules(ctx context.Context, req *pb.PackagesModulesReq) ([]*models.Module, error) ModulesProcess(ctx context.Context, td time.Duration) ([]*models.Module, error) PackagesProcess(ctx context.Context, td time.Duration) ([]*models.Package, error) PackagesCreate(ctx context.Context, req *pb.PackagesCreateReq) (*models.Package, error) PackagesList(ctx context.Context, req *pb.PackagesListReq) ([]*models.Package, error) PackagesLookup(ctx context.Context, req *pb.PackagesLookupReq) (*models.Package, error) PackagesUpdate(ctx context.Context, req *pb.PackagesUpdateReq) (*models.Package, error) PackagesDelete(ctx context.Context, req *pb.PackagesDeleteReq) error CommentsCreate(ctx context.Context, req *pb.CommentsCreateReq) (*models.Comment, error) CommentsDelete(ctx context.Context, req *pb.CommentsDeleteReq) error CommentsList(ctx context.Context, req *pb.CommentsListReq) ([]*models.Comment, error) ModulesList(ctx context.Context, req *pb.ModulesListReq) ([]*models.Module, error) ModulesCreate(ctx context.Context, modules []*models.Module) error } func NewStorage(name string, db *sqlx.DB) (Storage, error) { function, ok := storages[name] if !ok { return nil, errors.New("incorrect name store") } store := function(db) database, ok := store.(Storage) if !ok { return nil, errors.New("dont implements interface Storage") } return database, nil }