crawler_go/crawler.go
jackdaw@loafle.com ec814d7179 grpc proto file
2017-04-12 20:14:09 +09:00

64 lines
1.3 KiB
Go

package crawler
import "errors"
type Internal interface {
Internal(params map[string]interface{}) ([]byte, error)
}
type Crawler interface {
Init(path string) ([]byte,error)
Add(id string) ([]byte,error)
Remove(id string) ([]byte,error)
Get(id string) ([]byte,error)
}
type CrawlerImpl struct {
configs map[string]interface{}
internal Internal
}
func (c *CrawlerImpl) Init(path string) ([]byte,error) {
if c.configs == nil {
c.configs = make(map[string]interface{}, 0)
}
// load all file in path
return nil,nil
}
func (c *CrawlerImpl) Add(id string) ([]byte,error) {
//file load , input config
return nil,nil
}
func (c *CrawlerImpl) Remove(id string) ([]byte,error) {
//remove in config
return nil,nil
}
func (c *CrawlerImpl) Get(id string)([]byte,error) {
if c.internal != nil {
out, err := c.internal.Internal(c.GetConfig(id))
if err != nil {
//set error fail, message
return nil,err
}
return out, nil
}
return nil, errors.New("Not Assign")
}
// 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
}