优化 types in
This commit is contained in:
10
fileboy.go
10
fileboy.go
@@ -49,15 +49,19 @@ func parseConfig() {
|
|||||||
if cfg.Core.Version > Version {
|
if cfg.Core.Version > Version {
|
||||||
log.Panicln(PreError, "current fileboy support max version : ", Version)
|
log.Panicln(PreError, "current fileboy support max version : ", Version)
|
||||||
}
|
}
|
||||||
|
// types convert map
|
||||||
|
cfg.Monitor.TypesMap = map[string]bool{}
|
||||||
|
for _, v := range cfg.Monitor.Types {
|
||||||
|
cfg.Monitor.TypesMap[v] = true
|
||||||
|
}
|
||||||
log.Println(cfg)
|
log.Println(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func eventDispatcher(event fsnotify.Event) {
|
func eventDispatcher(event fsnotify.Event) {
|
||||||
ext := path.Ext(event.Name)
|
ext := path.Ext(event.Name)
|
||||||
if len(cfg.Monitor.Types) > 0 &&
|
if len(cfg.Monitor.Types) > 0 &&
|
||||||
cfg.Monitor.Types[0] != ".*" &&
|
!keyInMonitorTypesMap(".*", cfg) &&
|
||||||
!inStringArray(ext, cfg.Monitor.Types) {
|
!keyInMonitorTypesMap(ext, cfg) {
|
||||||
//log.Println(ext, cfg.Monitor.Types, inStringArray(ext, cfg.Monitor.Types))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch event.Op {
|
switch event.Op {
|
||||||
|
@@ -6,6 +6,7 @@ type FileGirl struct {
|
|||||||
}
|
}
|
||||||
Monitor struct {
|
Monitor struct {
|
||||||
Types []string `yaml:"types"`
|
Types []string `yaml:"types"`
|
||||||
|
TypesMap map[string]bool `yaml:"-"`
|
||||||
IncludeDirs []string `yaml:"includeDirs"`
|
IncludeDirs []string `yaml:"includeDirs"`
|
||||||
ExceptDirs []string `yaml:"exceptDirs"`
|
ExceptDirs []string `yaml:"exceptDirs"`
|
||||||
}
|
}
|
||||||
|
5
util.go
5
util.go
@@ -15,6 +15,11 @@ func inStringArray(value string, arr []string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func keyInMonitorTypesMap(k string, cfg *FileGirl) bool {
|
||||||
|
_, ok := cfg.Monitor.TypesMap[k]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
func cmdParse2Array(s string, cf *changedFile) []string {
|
func cmdParse2Array(s string, cf *changedFile) []string {
|
||||||
a := strings.Split(s, " ")
|
a := strings.Split(s, " ")
|
||||||
r := make([]string, 0)
|
r := make([]string, 0)
|
||||||
|
Reference in New Issue
Block a user