-
Notifications
You must be signed in to change notification settings - Fork 0
/
modules.go
69 lines (58 loc) · 1.27 KB
/
modules.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
package main
import (
"fmt"
iniset "github.com/liupeidong0620/pscf/ini"
jsonset "github.com/liupeidong0620/pscf/json"
yamlset "github.com/liupeidong0620/pscf/yaml"
)
type yamlAttribute struct {
ignoreField string
}
/*
interface
*/
type modules_st interface {
Set(params ...interface{}) error
Get(params ...interface{}) (interface{}, error)
GetKeys(params ...interface{}) (interface{}, error)
Del(params ...interface{}) error
Save() error
}
func modules_init(mod, file string) (modules_st, error) {
var module modules_st
var err error
switch mod {
case YAMLTOOL:
module, err = yamlset.Module_init(file)
if err != nil {
return nil, err
}
case JSONTOOL:
module, err = jsonset.Module_init(file)
if err != nil {
return nil, err
}
case INITOOL:
module, err = iniset.Module_init(file)
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("Unsupported configure file type: %s.", mod)
}
return module, err
}
func setYamlCommentEnable(enable bool) {
yamlset.SetCommentEnable(enable)
}
func set_module_attribute(mod string, ctx interface{}) error {
switch mod {
case YAMLTOOL:
if yamlAttr, ok := ctx.(yamlAttribute); ok {
return yamlset.SetIgnoreField(yamlAttr.ignoreField)
}
case JSONTOOL:
case INITOOL:
}
return nil
}