2017-04-10 09:03:31 +00:00
|
|
|
package crawler
|
|
|
|
|
|
|
|
import (
|
2017-04-10 11:15:47 +00:00
|
|
|
"loafle.com/overflow/of_rpc_go/models/param"
|
2017-04-10 09:03:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|