-
Notifications
You must be signed in to change notification settings - Fork 0
/
toml.go
58 lines (54 loc) · 1.23 KB
/
toml.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 main
import (
"fmt"
"github.com/BurntSushi/toml"
"os"
)
// Conf ...
type Conf struct {
Name string
CountI int32
CountJ int32
IsKilled bool
KillTime string
StartTime string
EndTime string
}
type CfConf struct {
KillProcessName string
AllowMinutesToPlay int32
}
func ReadConfigs(path string) (conf CfConf, err error) {
var config CfConf
if _, err := toml.DecodeFile(path, &config); err != nil {
fmt.Println(err)
}
return config, err
}
func WriteToml(path string, i int32, j int32, isKilled bool, killTime string, startTime string, endTime string) {
file, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR|os.O_TRUNC, os.ModePerm)
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
encode := toml.NewEncoder(file)
if err = encode.Encode(&Conf{Name: "gameCount", CountI: i, CountJ: j, IsKilled: isKilled, KillTime: killTime, StartTime: startTime, EndTime: endTime}); err != nil {
return
}
}
func ReadToml(path string) (conf Conf, err error) {
var config Conf
if _, err := toml.DecodeFile(path, &config); err != nil {
fmt.Println(err)
}
return config, err
}
func ExistsFile(path string) bool {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return false
} else {
return true
}
}