-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_config.go
59 lines (47 loc) · 1 KB
/
cmd_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
package vfsindex
import (
"os"
"path/filepath"
"github.com/BurntSushi/toml"
)
// ConfigFile undocumented
type ConfigFile struct {
Name2Index map[string]*ConfigIndex
}
//ConfigIndex undocumented
type ConfigIndex struct {
Path string
ConfigBase
}
// ConfigBase undocumented
type ConfigBase struct {
Dir string
IndexDir string
Table string
}
// SaveCmdConfig undocumented
func SaveCmdConfig(dir string, conf *ConfigFile) error {
f, err := os.OpenFile(filepath.Join(dir, "vfs-index.toml"), os.O_RDWR|os.O_CREATE, 0755)
defer f.Close()
if err != nil {
return err
}
if err := toml.NewEncoder(f).Encode(conf); err != nil {
return err
}
return nil
}
// LoadCmdConfig undocumented
func LoadCmdConfig(dir string) (*ConfigFile, error) {
f, err := os.Open(filepath.Join(dir, "vfs-index.toml"))
defer f.Close()
if err != nil {
return nil, err
}
conf := &ConfigFile{}
_, err = toml.DecodeFile(filepath.Join(dir, "vfs-index.toml"), conf)
if err != nil {
return nil, err
}
return conf, nil
}