forked from donge/xiaoshaozi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
84 lines (76 loc) · 1.44 KB
/
config.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
//"bufio"
"encoding/json"
"fmt"
//"io"
"io/ioutil"
"log"
"os"
)
type Config struct {
Id uint
Type uint
Port string
Email string
Password string
AccessKey string
SecurtKey string
Quick uint
Slow uint
QuickInit float64
SlowInit float64
Delta float64
Diff float64
Pulse uint
Clear bool
Simulator bool
Cash float64
Coin float64
}
const CONFIG_FILE = "config.json"
func SaveConfig(file_name string, config *Config) (err error) {
if file_name == "" {
file_name = CONFIG_FILE
}
fout, err := os.Create(file_name)
defer fout.Close()
if err != nil {
fmt.Println(fout, err)
return
}
/* pretty print */
b, err := json.MarshalIndent(config, "", " ")
if err != nil {
log.Println(err)
return
}
//fout.WriteString("Just a config!\r\n")
fout.Write(b)
log.Println("CONFIG SAVED.")
return
}
func LoadConfig(file_name string, config *Config) (err error) {
if file_name == "" {
file_name = CONFIG_FILE
}
file, err := os.Open(file_name) // For read access.
defer file.Close()
if err != nil {
log.Fatal(err)
}
//r := bufio.NewReader(file)
//meta_json := r.ReadBytes(io.EOF)
meta_json, err := ioutil.ReadAll(file)
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(meta_json, config)
if err != nil {
log.Panic(err)
}
/*ra, _ := ioutil.ReadFile("C:\\Windows\\win.ini")*/
//fmt.Println(config)
log.Println("CONFIG LOADED.")
return
}