/
config.go
47 lines (40 loc) · 836 Bytes
/
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
//----------------------------------------
//
// Copyright © ying32. All Rights Reserved.
//
// Licensed under Apache License 2.0
//
//----------------------------------------
package main
import (
"encoding/json"
"io/ioutil"
"os"
"github.com/ying32/govcl/vcl/rtl"
)
type TConnConfig struct {
Name string
Host string
Port int
Password string
}
// 全局配置
var (
appConfFileName = rtl.ExtractFilePath(os.Args[0]) + "app.conf"
config = make(map[string]TConnConfig, 0)
)
func saveConfig() {
bs, err := json.Marshal(config)
if err == nil {
ioutil.WriteFile(appConfFileName, bs, 0664)
}
}
func loadConfig() {
config = make(map[string]TConnConfig, 0)
if rtl.FileExists(appConfFileName) {
bs, err := ioutil.ReadFile(appConfFileName)
if err == nil {
json.Unmarshal(bs, &config)
}
}
}