Organize backend into product executable and shared Go modules
This commit is contained in:
1 parent
981e84a4b4
commit
f0720ec66b
382 files changed
+1944
-6989
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"git.sendico.io/tech/sxchnge/shared/database"
|
||||
"git.sendico.io/tech/sxchnge/shared/database/transaction"
|
||||
"git.sendico.io/tech/sxchnge/shared/errors"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
// Dependencies resolves local DB/transaction primitives for edge-local store wiring only.
|
||||
type Dependencies struct {
|
||||
Database *mongo.Database
|
||||
Transactions transaction.Factory
|
||||
}
|
||||
|
||||
type DatabaseProvider interface {
|
||||
MongoDatabase() *mongo.Database
|
||||
}
|
||||
|
||||
func ResolveDependencies(dbf db.Factory) (*Dependencies, error) {
|
||||
if dbf == nil {
|
||||
return nil, merrors.InvalidArgument("database factory is required", "dbFactory")
|
||||
}
|
||||
|
||||
provider, ok := dbf.(DatabaseProvider)
|
||||
if !ok || provider.MongoDatabase() == nil {
|
||||
return nil, merrors.Internal("mongo database provider is not available for edge-local storage wiring")
|
||||
}
|
||||
|
||||
return &Dependencies{
|
||||
Database: provider.MongoDatabase(),
|
||||
Transactions: dbf.TransactionFactory(),
|
||||
}, nil
|
||||
}
|
||||
Reference in new issue
Block a user