Documentation ¶
Index ¶
- Constants
- Variables
- func MaskedMongoConnectionURL(mc *MongoDBCredentials) string
- func MongoConnectionURL(mc *MongoDBCredentials) string
- type ConnectionManager
- type ConnectionOpts
- type MongoDBCredentials
- type MongoDatabase
- type MongoManager
- type OrdersDataService
- type OrdersRepo
- func (o *OrdersRepo) Create(ctx context.Context, po *data.Order) (string, error)
- func (o *OrdersRepo) DeleteByID(ctx context.Context, id primitive.ObjectID) error
- func (o *OrdersRepo) GetAll(ctx context.Context, limit int64) (*[]data.Order, error)
- func (o *OrdersRepo) GetByID(ctx context.Context, oID primitive.ObjectID) (*data.Order, error)
- func (o *OrdersRepo) Update(ctx context.Context, po *data.Order) error
Constants ¶
View Source
const ( DefConnectionTimeOut = 10 * time.Second DefDatabase = "ecommerce" )
View Source
const ( OrdersCollection = "purchaseOrders" DefaultPageSize = 100 )
View Source
const DefaultMongoDBSidecar string = "/secrets/db.json"
Variables ¶
View Source
var ( ErrInvalidConnURL = errors.New("failed to connect to DB:as the connection string is invalid") ErrConnectionEstablish = errors.New("failed to establish connection to DB") ErrClientInit = errors.New("failed to initialize db client") ErrConnectionLeak = errors.New("unable to disconnect from DB, connection leak") ErrPingDB = errors.New("failed to ping DB") )
View Source
var ( ErrSideCarFileFormat = errors.New("mongo side car file is in invalid format") ErrSideCarFileRead = errors.New("failed to read mongo side car file") )
View Source
var ( ErrInvalidInitialization = errors.New("invalid initialization") ErrInvalidPOIDCreate = errors.New("order id should be empty") ErrInvalidPOIDUpdate = errors.New("invalid order id") ErrUnexpectedUpdateOrder = errors.New("unexpected error occurred while updating order") ErrPOIDNotFound = errors.New("purchase order doesn't exist with given id") ErrFailedToCreateOrder = errors.New("faild to create order") ErrUnexpectedDeleteOrder = errors.New("unexpected error occurred while deleting orfer") )
Functions ¶
func MaskedMongoConnectionURL ¶
func MaskedMongoConnectionURL(mc *MongoDBCredentials) string
func MongoConnectionURL ¶
func MongoConnectionURL(mc *MongoDBCredentials) string
Types ¶
type ConnectionManager ¶
type ConnectionManager struct {
// contains filtered or unexported fields
}
func NewMongoManager ¶
func NewMongoManager(mc *MongoDBCredentials, opts *ConnectionOpts, lgr *logger.AppLogger) (*ConnectionManager, error)
func (*ConnectionManager) Database ¶
func (c *ConnectionManager) Database() MongoDatabase
func (*ConnectionManager) Disconnect ¶
func (c *ConnectionManager) Disconnect() error
func (*ConnectionManager) NewClient ¶
func (c *ConnectionManager) NewClient(connOpts *ConnectionOpts) (*mongo.Client, error)
func (*ConnectionManager) Ping ¶
func (c *ConnectionManager) Ping() error
type ConnectionOpts ¶
func FillConnectionOpts ¶
func FillConnectionOpts(opts *ConnectionOpts) *ConnectionOpts
type MongoDBCredentials ¶
type MongoDBCredentials struct { User string `json:"user"` Port string `json:"port"` HostName string `json:"hostname"` ReplicaSet string `json:"replicaset"` Password string `json:"password"` }
func MongoDBCredentialFromSideCar ¶
func MongoDBCredentialFromSideCar(sideCarFile string) (*MongoDBCredentials, error)
type MongoDatabase ¶
type MongoDatabase interface {
Collection(name string, opts ...*options.CollectionOptions) *mongo.Collection
}
type MongoManager ¶
type MongoManager interface { Database() MongoDatabase Ping() error Disconnect() error }
type OrdersDataService ¶
type OrdersDataService interface { Create(ctx context.Context, purchaseOrder *data.Order) (string, error) Update(ctx context.Context, purchaseOrder *data.Order) error GetAll(ctx context.Context, limit int64) (*[]data.Order, error) GetByID(ctx context.Context, id primitive.ObjectID) (*data.Order, error) DeleteByID(ctx context.Context, id primitive.ObjectID) error }
type OrdersRepo ¶
type OrdersRepo struct {
// contains filtered or unexported fields
}
func NewOrderRepo ¶
func NewOrderRepo(db MongoDatabase, lgr *logger.AppLogger) *OrdersRepo
func (*OrdersRepo) DeleteByID ¶
Click to show internal directories.
Click to hide internal directories.