Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrGeneralDBFail = errors.New("unexpected database error")
ErrGeneralDBFail is used to hide db errors from client
Functions ¶
This section is empty.
Types ¶
type Customer ¶
type Customer struct { Id int `json:"id,omitempty"` FirstName string `json:"firstName,omitempty" validate:"required,max=50"` LastName string `json:"lastName,omitempty" validate:"required,max=50"` Age int `json:"age,omitempty" validate:"required,gt=0,max=150"` Orders []*Order `json:"orders,omitempty"` }
Customer model
type EntityError ¶
EntityError represents all errors that can be exposed to the user, for example "order/product/customer not found"
func ErrNotFound ¶
func ErrNotFound(entity string, id int) *EntityError
ErrNotFound composes "not found" errors for provided entities
func ErrOutOfInventory ¶
func ErrOutOfInventory(entity string, id int) *EntityError
ErrOutOfInventory composes "out of inventory" errors for provided entities
func (*EntityError) Error ¶
func (e *EntityError) Error() string
type Order ¶
type Order struct { Id int `json:"id,omitempty"` Date time.Time `json:"date,omitempty"` NetAmount float64 `json:"netamount,omitempty"` Tax float64 `json:"tax,omitempty"` TotalAmount float64 `json:"totalamount,omitempty"` Products []*Product `json:"products,omitempty"` }
Order model
type Product ¶
type Product struct { Id int `json:"id,omitempty" validate:"required,gte=0,int"` Title string `json:"title,omitempty" validate:"required,max=50"` Price float64 `json:"price,omitempty" validate:"required,gte=0,float"` Quantity int `json:"quantity,omitempty" validate:"required,gte=0,int"` }
Product model
func ProductFromProto ¶
ProductFromProto maps proto.Product to models.Product
type SortById ¶
type SortById []*Product
SortById implements sort.Interface and is used to sort slice of products by id
type Validation ¶
type Validation struct {
*validator.Validate
}
Validation embeds validator and has custom validations
func NewValidation ¶
func NewValidation() *Validation
NewValidation creates new validator and registers custom validations
type ValidationError ¶
type ValidationError struct {
Message string
}
ValidationError represents validation errors
func ErrFieldsNotValid ¶
func ErrFieldsNotValid(fieldNames ...string) *ValidationError
ErrFieldsNotValid composes validation error with provided fields
func (*ValidationError) Error ¶
func (v *ValidationError) Error() string