overflow_probe_container_ne.../service/ConfigService.go
crusader 900a5c42dd ing
2017-12-14 15:17:58 +09:00

48 lines
986 B
Go

package service
import (
configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
"git.loafle.net/overflow/overflow_probe_container_network/crawler/impl"
)
type ConfigService struct {
}
func (s *ConfigService) Add(crawlerName string, config *configM.Config) error {
c := impl.GetCrawler(crawlerName)
return c.Add(config)
}
func (s *ConfigService) Remove(crawlerName string, id string) error {
c := impl.GetCrawler(crawlerName)
return c.Remove(id)
}
func (s *ConfigService) Init(configs []map[string]*configM.Config) error {
var err error
sensorIDs := make([]map[string]*configM.Config, 0)
ok := true
Loop:
for _, item := range configs {
for k, v := range item {
c := impl.GetCrawler(k)
if err = c.Init(v); nil != err {
ok = false
break Loop
}
sensorIDs = append(sensorIDs, item)
}
}
if !ok {
for _, item := range sensorIDs {
for k, v := range item {
s.Remove(k, v.ID.String())
}
}
return err
}
return nil
}