-
Notifications
You must be signed in to change notification settings - Fork 4
/
product.go
58 lines (51 loc) · 991 Bytes
/
product.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package product
import "time"
// ProductCategory represents the categories of electronic products
type ProductCategory int
// Enumeration of product categories
const (
Laptop ProductCategory = iota
Smartphone
Tablet
SmartWatch
Headphones
Camera
Television
Other
)
// String representation of the ProductCategory
func (p ProductCategory) String() string {
return [...]string{
"Laptop",
"Smartphone",
"Tablet",
"SmartWatch",
"Headphones",
"Camera",
"Television",
"Other",
}
}
// Const for error messages
const (
ErrorSkuExists string = "ERROR_SKU_EXISTS"
ErrorWrongCategory string = "ERROR_WRONG_CATEGORY"
)
// Product Domain
type User struct {
Id int
Name string
Sku string
Category ProductCategory
Price string
CreatedAt time.Time
}
// Create a new product instance
func New(n string, s string, c string, p string) (*Product, error) {
return &Product{
Name: n,
Sku: s,
Category: c,
Price: p,
}, nil
}