overflow_probe_container_ne.../crawler/crawler.go
crusader ae5c6f324f ing
2017-12-13 23:10:52 +09:00

69 lines
1.4 KiB
Go

package crawler
import (
configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
)
type Crawler interface {
Init(config *configM.Config) (bool, error)
Add(config *configM.Config) (bool, error)
Remove(id string) (bool, error)
Get(id string) (map[string]string, error)
Name() string
}
type InternalCrawler interface {
InternalGet(config *configM.Config) (map[string]string, error)
}
type Crawlers struct {
configs map[string]*configM.Config
Internal InternalCrawler
}
func (c *Crawlers) GetConfig(id string) *configM.Config {
if nil == c.configs {
return nil
}
return c.configs[id]
}
func (c *Crawlers) RemoveConfig(id string) {
if nil == c.configs {
return
}
delete(c.configs, id)
}
func (c *Crawlers) PutConfig(id string, config *configM.Config) {
if nil == c.configs {
c.configs = make(map[string]*configM.Config, 0)
}
c.configs[id] = config
}
func (c *Crawlers) Init(config *configM.Config) (bool, error) {
c.PutConfig(config.ID.String(), config)
return true, nil
}
func (c *Crawlers) Add(config *configM.Config) (bool, error) {
c.PutConfig(config.ID.String(), config)
return true, nil
}
func (c *Crawlers) Remove(id string) (bool, error) {
c.RemoveConfig(id)
return true, nil
}
func (c *Crawlers) Get(id string) (map[string]string, error) {
rss, err := c.Internal.InternalGet(c.GetConfig(id))
if nil != err {
return nil, err
}
return rss, nil
}