-
Notifications
You must be signed in to change notification settings - Fork 1
/
TaskProducts.go
50 lines (40 loc) · 1015 Bytes
/
TaskProducts.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
package Tasks
import (
"encoding/gob"
"github.com/CloudWise-OpenSource/GoCrab/Api"
"github.com/CloudWise-OpenSource/GoCrab/Helpers"
"github.com/SeasX/SeasConfig/Enums"
"os"
)
func LoadProducts(products interface{}) error {
GoCrab.Debug("LoadProducts Start")
productDbFile := Enums.GetDBProductsFile()
if !Helpers.FileExists(productDbFile) {
GoCrab.Warn("LoadProducts Do not exists", productDbFile)
return nil
}
file, err := os.Open(productDbFile)
if err == nil {
decoder := gob.NewDecoder(file)
err = decoder.Decode(products)
}
if err != nil {
GoCrab.Error("LoadProducts Error", productDbFile, err)
} else {
GoCrab.Debug("LoadProducts Complete")
}
file.Close()
return err
}
func SaveProducts(products interface{}) error {
file, err := os.Create(Enums.GetDBProductsFile())
if err == nil {
encoder := gob.NewEncoder(file)
encoder.Encode(products)
GoCrab.Debug("SaveProducts Successful")
} else {
GoCrab.Error("SaveProducts Error", err)
}
file.Close()
return err
}