Documentation
¶
Index ¶
- Variables
- func FromJSON(i interface{}, r io.Reader) error
- func GetgrpcClient(s string, l *zap.Logger) *grpc.ClientConn
- func ToJSON(i interface{}, w io.Writer) error
- type Product
- type Products
- type ProductsDB
- func (db *ProductsDB) AddProduct(ctx context.Context, d []interface{}) (*mongo.InsertManyResult, error)
- func (db *ProductsDB) DeleteProduct(ctx context.Context, id primitive.ObjectID) error
- func (db *ProductsDB) DisconnectMongoClient() error
- func (db *ProductsDB) GetMongoClient(m string) (*mongo.Client, error)
- func (db *ProductsDB) GetMongoCollection(dbase string, coll string) error
- func (db *ProductsDB) GetProductByID(ctx context.Context, id primitive.ObjectID, currency string) (*Product, error)
- func (db *ProductsDB) GetProducts(ctx context.Context, currency string) (Products, error)
- func (db *ProductsDB) MigrateDocs(ctx context.Context) (*mongo.InsertManyResult, error)
- func (db *ProductsDB) UpdateProduct(ctx context.Context, p []*Product, id primitive.ObjectID) (*mongo.BulkWriteResult, error)
- type Validation
- type ValidationError
- type ValidationErrors
Constants ¶
This section is empty.
Variables ¶
var ErrProductNotFound = fmt.Errorf("product not found")
var ProductList = productList
Functions ¶
func GetgrpcClient ¶
func GetgrpcClient(s string, l *zap.Logger) *grpc.ClientConn
Types ¶
type Product ¶
type Product struct {
// the id for the product
//
// required: false
// min: 1
ID string `json:"id,omitempty" bson:"_id,omitempty"`
// the name for this poduct
//
// required: true
// max length: 255
Name string `json:"name" bson:"name" validate:"required"`
// the description for this poduct
//
// required: false
// max length: 10000
Description string `json:"description" bson:"description,omitempty"`
// the price for the product
//
// required: true
// min: 0.01
Price float64 `json:"price" bson:"price" validate:"gt=0"`
// the SKU for the product
//
// required: true
// pattern: [a-z]+-[a-z]+-[a-z]+
SKU string `json:"sku" bson:"sku" validate:"required,sku"`
}
Product defines the structure for an API product
type ProductsDB ¶
type ProductsDB struct {
// contains filtered or unexported fields
}
func GetProductsDB ¶
func GetProductsDB(c protos.CurrencyClient, l *zap.Logger, mc *mongo.Client) *ProductsDB
func (*ProductsDB) AddProduct ¶
func (db *ProductsDB) AddProduct(ctx context.Context, d []interface{}) (*mongo.InsertManyResult, error)
AddProduct adds a new product to the database
func (*ProductsDB) DeleteProduct ¶
DeleteProduct deletes a product from the database
func (*ProductsDB) DisconnectMongoClient ¶
func (db *ProductsDB) DisconnectMongoClient() error
func (*ProductsDB) GetMongoClient ¶
func (db *ProductsDB) GetMongoClient(m string) (*mongo.Client, error)
func (*ProductsDB) GetMongoCollection ¶
func (db *ProductsDB) GetMongoCollection(dbase string, coll string) error
func (*ProductsDB) GetProductByID ¶
func (db *ProductsDB) GetProductByID(ctx context.Context, id primitive.ObjectID, currency string) (*Product, error)
GetProductByID returns a single product which matches the id from the database. If a product is not found this function returns a ProductNotFound error
func (*ProductsDB) GetProducts ¶
GetProducts returns all products from the database
func (*ProductsDB) MigrateDocs ¶
func (db *ProductsDB) MigrateDocs(ctx context.Context) (*mongo.InsertManyResult, error)
func (*ProductsDB) UpdateProduct ¶
func (db *ProductsDB) UpdateProduct(ctx context.Context, p []*Product, id primitive.ObjectID) (*mongo.BulkWriteResult, error)
UpdateProduct replaces a product in the database with the given item. If a product with the given id does not exist in the database this function returns a ProductNotFound error
type Validation ¶
type Validation struct {
// contains filtered or unexported fields
}
Validation contains a validate
func (*Validation) Validate ¶
func (v *Validation) Validate(i interface{}) ValidationErrors
Validate the item
type ValidationError ¶
type ValidationError struct {
FieldError validator.FieldError
}
ValidationError wraps the validator.FieldError so it is not exposed to our code
func (ValidationError) Error ¶
func (v ValidationError) Error() string
type ValidationErrors ¶
type ValidationErrors []ValidationError
ValidationErrors is a collection of ValidationError
func (ValidationErrors) Errors ¶
func (v ValidationErrors) Errors() []string
Errors converts the slice into a string slice