crawler_go/crawler.go
jackdaw@loafle.com 031ba9e162 .
2017-04-10 20:15:47 +09:00

67 lines
1.4 KiB
Go

package crawler
import (
"loafle.com/overflow/of_rpc_go/models/param"
)
type Internal interface {
Internal(params map[string]interface{}) (param.Output, error)
}
type Crawler interface {
Init(path string, result *param.Output) error
Add(id string, result *param.Output) error
Remove(id string, result *param.Output) error
Get(id string, result *param.Output) error
}
type CrawlerImpl struct {
configs map[string]interface{}
internal Internal
}
func (c *CrawlerImpl) Init(path string, result *param.Output) error {
if c.configs == nil {
c.configs = make(map[string]interface{}, 0)
}
// load all file in path
return nil
}
func (c *CrawlerImpl) Add(id string, result *param.Output) error {
//file load , input config
return nil
}
func (c *CrawlerImpl) Remove(id string, result *param.Output) error {
//remove in config
return nil
}
func (c *CrawlerImpl) Get(id string, result *param.Output) error {
if c.internal != nil {
out, err := c.internal.Internal(c.GetConfig(id))
if err != nil {
//set error fail, message
}
*result = out
}
return nil
}
// internal methods
func (c *CrawlerImpl) GetConfig(id string) map[string]interface{} {
return c.configs[id].(map[string]interface{})
}
func (c *CrawlerImpl) SetInternal(i Internal) {
c.internal = i
}
func (c *CrawlerImpl) PutConfig(name string, m map[string]interface{}) {
if c.configs == nil {
c.configs = make(map[string]interface{}, 0)
}
c.configs[name] = m
}