-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmega_io.go
70 lines (61 loc) · 1.38 KB
/
mega_io.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
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
)
func GenConfigName() string {
return filepath.Join(megaWorkspace, configName)
}
//Config functions
func SaveConfig(v interface{}) error {
ShouldLock()
str := mResponse(v)
pathoffile := GenConfigName()
strbytes := []byte(str)
err := ioutil.WriteFile(pathoffile, strbytes, 0700)
strbytes = nil
ShouldUnlock()
return err
}
func LoadConfig(targ interface{}) error {
ShouldLock()
pathoffile := GenConfigName()
data, err := ioutil.ReadFile(pathoffile)
if err != nil {
return err
}
err = json.Unmarshal(data, targ)
ShouldUnlock()
return err
}
func ParsePodMetricList(targ interface{}, data []byte) error {
err := json.Unmarshal(data, targ)
return err
}
func GenLogName(name string) string {
return filepath.Join(megaWorkspace, logDirectory, name)
}
// Server request log functions
func SaveLog(name string, v interface{}) error {
str := mResponse(v)
pathoffile := GenLogName(name)
strbytes := []byte(str)
err := ioutil.WriteFile(pathoffile, strbytes, 0700)
strbytes = nil
return err
}
func LoadLog(name string, targ interface{}) error {
pathoffile := GenLogName(name)
data, err := ioutil.ReadFile(pathoffile)
if err != nil {
return err
}
err = json.Unmarshal(data, targ)
return err
}
func DeleteLog(name string) {
pathoffile := filepath.Join(megaWorkspace, logDirectory, name)
os.Remove(pathoffile)
}