This repository has been archived by the owner on Mar 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
catalog.go
72 lines (60 loc) · 1.44 KB
/
catalog.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
package config
import (
"github.com/vaughan0/go-ini"
"strings"
)
type CatalogConf struct {
Name string `json:"name"`
Path string `json:"path"`
IgnoreSuffixs []string `json:"ignore_suffix"`
IgnoreRegexp []string `json:"ignore_regexp"`
ChildFile []string `json:"child_file"`
}
func (cf *CatalogConf) HasChildFile(childfile string) (ok bool) {
for _, file := range cf.ChildFile {
if file == childfile {
return true
}
}
return false
}
func (cf *CatalogConf) FullFilePath(filePath string) string {
return cf.Path + "/" + filePath
}
func (cf *CatalogConf) Check() (err error) {
return nil
}
func LoadAllCatalogFromIni(content string) (catalogs map[string]*CatalogConf, err error) {
conf, errRet := ini.Load(strings.NewReader(content))
if errRet != nil {
err = errRet
return
}
var (
tmpStr string
ok bool
)
catalogs = make(map[string]*CatalogConf)
for name, section := range conf {
if name == "common" {
continue
}
catalog := CatalogConf{
Name: name,
}
if tmpStr, ok = section["path"]; ok {
if len(tmpStr) > 1 && strings.HasSuffix(tmpStr, "/") {
tmpStr = tmpStr[:len(tmpStr)-1]
}
catalog.Path = tmpStr
}
if tmpStr, ok = section["ignore_suffix"]; ok {
catalog.IgnoreSuffixs = ParseIgnoreSuffix(tmpStr)
}
if tmpStr, ok = section["ignore_regexp"]; ok {
catalog.IgnoreRegexp = ParseIgnoreRegexp(tmpStr)
}
catalogs[name] = &catalog
}
return catalogs, nil
}