parameter
This commit is contained in:
snoop 2017-04-27 19:42:46 +09:00
parent b565969109
commit 46529a530f
5 changed files with 141 additions and 86 deletions

View File

@ -3,7 +3,7 @@ package crawler
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"io/ioutil"
"log" "log"
"loafle.com/overflow/crawler_go/config" "loafle.com/overflow/crawler_go/config"
) )
@ -13,8 +13,8 @@ type Internal interface {
} }
type Crawler interface { type Crawler interface {
Init(path string) ([]byte, error) Init(path []byte) ([]byte, error)
Add(id string) ([]byte, error) Add(data []byte) ([]byte, error)
Remove(id string) ([]byte, error) Remove(id string) ([]byte, error)
Get(id string) ([]byte, error) Get(id string) ([]byte, error)
} }
@ -23,43 +23,29 @@ type CrawlerImpl struct {
Crawler Crawler
configs map[string] config.Config configs map[string] config.Config
internal Internal internal Internal
configPath string
} }
func (c *CrawlerImpl) Init(path string) ([]byte, error) { func (c *CrawlerImpl) Init(data []byte) ([]byte, error) {
if c.configs == nil { if c.configs == nil {
c.configs = make(map[string]config.Config, 0) c.configs = make(map[string]config.Config, 0)
} }
c.configPath = path _,err := c.Add(data)
files, err := ioutil.ReadDir(c.configPath)
if err != nil { if err != nil {
log.Panic(err) log.Fatal(err)
} }
for _, file := range files {
if file.IsDir() == true {
continue
}
_,err := c.Add(file.Name())
if err != nil {
log.Panic(err)
}
}
// load all file in path // load all file in path
return json.Marshal(true) return json.Marshal(true)
} }
func (c *CrawlerImpl) Add(id string) ([]byte, error) { func (c *CrawlerImpl) Add(data []byte) ([]byte, error) {
b, err := ioutil.ReadFile(c.configPath + id)
if err != nil {
log.Panic(err)
}
var m = config.Config{} var m = config.Config{}
json.Unmarshal(b, &m) json.Unmarshal(data, &m)
c.configs[id] = m c.configs[m.Id] = m
return json.Marshal(true) return json.Marshal(true)
} }
@ -94,3 +80,5 @@ func (c *CrawlerImpl) PutConfig(name string, m config.Config) {
} }
c.configs[name] = m c.configs[name] = m
} }

View File

@ -14,6 +14,7 @@ It has these top-level messages:
InputArray InputArray
Init Init
Input Input
InputAdd
Output Output
*/ */
package grpc package grpc
@ -188,7 +189,7 @@ func (m *InputArray) GetIn() []*Init {
type Init struct { type Init struct {
Name Crawlers `protobuf:"varint,1,opt,name=name,enum=Crawlers" json:"name,omitempty"` Name Crawlers `protobuf:"varint,1,opt,name=name,enum=Crawlers" json:"name,omitempty"`
Path string `protobuf:"bytes,2,opt,name=path" json:"path,omitempty"` Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
} }
func (m *Init) Reset() { *m = Init{} } func (m *Init) Reset() { *m = Init{} }
@ -203,11 +204,11 @@ func (m *Init) GetName() Crawlers {
return Crawlers_HEALTH_ACTIVEDIRECTORY return Crawlers_HEALTH_ACTIVEDIRECTORY
} }
func (m *Init) GetPath() string { func (m *Init) GetData() []byte {
if m != nil { if m != nil {
return m.Path return m.Data
} }
return "" return nil
} }
type Input struct { type Input struct {
@ -234,6 +235,30 @@ func (m *Input) GetId() string {
return "" return ""
} }
type InputAdd struct {
Name Crawlers `protobuf:"varint,1,opt,name=name,enum=Crawlers" json:"name,omitempty"`
Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
}
func (m *InputAdd) Reset() { *m = InputAdd{} }
func (m *InputAdd) String() string { return proto.CompactTextString(m) }
func (*InputAdd) ProtoMessage() {}
func (*InputAdd) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
func (m *InputAdd) GetName() Crawlers {
if m != nil {
return m.Name
}
return Crawlers_HEALTH_ACTIVEDIRECTORY
}
func (m *InputAdd) GetData() []byte {
if m != nil {
return m.Data
}
return nil
}
// response models // response models
type Output struct { type Output struct {
StartDate int64 `protobuf:"varint,1,opt,name=startDate" json:"startDate,omitempty"` StartDate int64 `protobuf:"varint,1,opt,name=startDate" json:"startDate,omitempty"`
@ -244,7 +269,7 @@ type Output struct {
func (m *Output) Reset() { *m = Output{} } func (m *Output) Reset() { *m = Output{} }
func (m *Output) String() string { return proto.CompactTextString(m) } func (m *Output) String() string { return proto.CompactTextString(m) }
func (*Output) ProtoMessage() {} func (*Output) ProtoMessage() {}
func (*Output) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} } func (*Output) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
func (m *Output) GetStartDate() int64 { func (m *Output) GetStartDate() int64 {
if m != nil { if m != nil {
@ -273,6 +298,7 @@ func init() {
proto.RegisterType((*InputArray)(nil), "InputArray") proto.RegisterType((*InputArray)(nil), "InputArray")
proto.RegisterType((*Init)(nil), "Init") proto.RegisterType((*Init)(nil), "Init")
proto.RegisterType((*Input)(nil), "Input") proto.RegisterType((*Input)(nil), "Input")
proto.RegisterType((*InputAdd)(nil), "InputAdd")
proto.RegisterType((*Output)(nil), "Output") proto.RegisterType((*Output)(nil), "Output")
proto.RegisterEnum("Crawlers", Crawlers_name, Crawlers_value) proto.RegisterEnum("Crawlers", Crawlers_name, Crawlers_value)
} }
@ -288,7 +314,7 @@ const _ = grpc1.SupportPackageIsVersion4
// Client API for Config service // Client API for Config service
type ConfigClient interface { type ConfigClient interface {
Add(ctx context.Context, in *Input, opts ...grpc1.CallOption) (*Output, error) Add(ctx context.Context, in *InputAdd, opts ...grpc1.CallOption) (*Output, error)
Remove(ctx context.Context, in *Input, opts ...grpc1.CallOption) (*Output, error) Remove(ctx context.Context, in *Input, opts ...grpc1.CallOption) (*Output, error)
Init(ctx context.Context, in *InputArray, opts ...grpc1.CallOption) (*Output, error) Init(ctx context.Context, in *InputArray, opts ...grpc1.CallOption) (*Output, error)
} }
@ -301,7 +327,7 @@ func NewConfigClient(cc *grpc1.ClientConn) ConfigClient {
return &configClient{cc} return &configClient{cc}
} }
func (c *configClient) Add(ctx context.Context, in *Input, opts ...grpc1.CallOption) (*Output, error) { func (c *configClient) Add(ctx context.Context, in *InputAdd, opts ...grpc1.CallOption) (*Output, error) {
out := new(Output) out := new(Output)
err := grpc1.Invoke(ctx, "/Config/Add", in, out, c.cc, opts...) err := grpc1.Invoke(ctx, "/Config/Add", in, out, c.cc, opts...)
if err != nil { if err != nil {
@ -331,7 +357,7 @@ func (c *configClient) Init(ctx context.Context, in *InputArray, opts ...grpc1.C
// Server API for Config service // Server API for Config service
type ConfigServer interface { type ConfigServer interface {
Add(context.Context, *Input) (*Output, error) Add(context.Context, *InputAdd) (*Output, error)
Remove(context.Context, *Input) (*Output, error) Remove(context.Context, *Input) (*Output, error)
Init(context.Context, *InputArray) (*Output, error) Init(context.Context, *InputArray) (*Output, error)
} }
@ -341,7 +367,7 @@ func RegisterConfigServer(s *grpc1.Server, srv ConfigServer) {
} }
func _Config_Add_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc1.UnaryServerInterceptor) (interface{}, error) { func _Config_Add_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc1.UnaryServerInterceptor) (interface{}, error) {
in := new(Input) in := new(InputAdd)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
@ -353,7 +379,7 @@ func _Config_Add_Handler(srv interface{}, ctx context.Context, dec func(interfac
FullMethod: "/Config/Add", FullMethod: "/Config/Add",
} }
handler := func(ctx context.Context, req interface{}) (interface{}, error) { handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ConfigServer).Add(ctx, req.(*Input)) return srv.(ConfigServer).Add(ctx, req.(*InputAdd))
} }
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
@ -546,41 +572,41 @@ var _Status_serviceDesc = grpc1.ServiceDesc{
func init() { proto.RegisterFile("grpc.proto", fileDescriptor0) } func init() { proto.RegisterFile("grpc.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{ var fileDescriptor0 = []byte{
// 569 bytes of a gzipped FileDescriptorProto // 576 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x93, 0x4f, 0x6f, 0x9b, 0x4c, 0x1f, 0x8b, 0x08, 0x00, 0x00,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 0x8c, 0xea, 0x03, 0x00, 0x00, 0xf1, 0x70, 0xfe, 0x27, 0x00, 0x00, 0xff, 0xff, 0xe6, 0x5f, 0x44, 0x44, 0x2c, 0x04, 0x00, 0x00,
} }

View File

@ -37,7 +37,7 @@ enum Crawlers {
// services // services
service Config { service Config {
rpc Add (Input) returns (Output) {} rpc Add (InputAdd) returns (Output) {}
rpc Remove (Input) returns (Output) {} rpc Remove (Input) returns (Output) {}
rpc Init (InputArray) returns (Output) {} rpc Init (InputArray) returns (Output) {}
} }
@ -62,7 +62,7 @@ message InputArray {
message Init { message Init {
Crawlers name = 1; Crawlers name = 1;
string path = 2; bytes data = 2;
} }
message Input { message Input {
@ -70,6 +70,11 @@ message Input {
string id =2; string id =2;
} }
message InputAdd {
Crawlers name = 1;
bytes data =2;
}
// response models // response models
message Output { message Output {
int64 startDate = 1; int64 startDate = 1;

View File

@ -7,12 +7,16 @@ import (
"loafle.com/overflow/crawler_go/health_crawler/redis_protocol_crawler_go" "loafle.com/overflow/crawler_go/health_crawler/redis_protocol_crawler_go"
"loafle.com/overflow/crawler_go" "loafle.com/overflow/crawler_go"
"io/ioutil"
) )
func initConfig() crawler.CrawlerImpl{ func initConfig() crawler.CrawlerImpl{
c := crawler.CrawlerImpl{} c := crawler.CrawlerImpl{}
c.SetInternal(redis_protocol_crawler_go.NewRedisHeahthCrawler()) c.SetInternal(redis_protocol_crawler_go.NewRedisHeahthCrawler())
c.Init("./")
b, _ := ioutil.ReadFile("./example.json")
c.Init(b)
return c return c
} }
@ -20,16 +24,17 @@ func initConfig() crawler.CrawlerImpl{
func TestCrawlerInit(t *testing.T) { func TestCrawlerInit(t *testing.T) {
c := initConfig() c := initConfig()
m := c.GetConfig("example.json") m := c.GetConfig("test_id_001")
assert.Equal(t, m.Id , "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734") assert.Equal(t, m.Id , "test_id_001")
} }
func TestCrawlerAdd(t *testing.T) { func TestCrawlerAdd(t *testing.T) {
c := initConfig() c := initConfig()
c.Remove("example.json") c.Remove("test_id_001")
b , _ := c.Add("example.json") bb, _ := ioutil.ReadFile("./example.json")
b , _ := c.Add(bb)
var ck bool var ck bool
json.Unmarshal(b,&ck) json.Unmarshal(b,&ck)
@ -40,7 +45,7 @@ func TestCrawlerAdd(t *testing.T) {
func TestCrawlerRemove(t *testing.T) { func TestCrawlerRemove(t *testing.T) {
c := initConfig() c := initConfig()
b, _ := c.Remove("example.json") b, _ := c.Remove("test_id_001")
var ck bool var ck bool
json.Unmarshal(b,&ck) json.Unmarshal(b,&ck)
@ -50,7 +55,7 @@ func TestCrawlerRemove(t *testing.T) {
func TestCrawlerGet(t *testing.T) { func TestCrawlerGet(t *testing.T) {
c := initConfig() c := initConfig()
b, _ := c.Get("example.json") b, _ := c.Get("test_id_001")
var ck bool var ck bool
json.Unmarshal(b,&ck) json.Unmarshal(b,&ck)
@ -59,3 +64,34 @@ func TestCrawlerGet(t *testing.T) {
} }
func TestFolder(t *testing.T) {
configPath := "./"
files, err := ioutil.ReadDir(configPath)
if err != nil {
t.Log(err)
}
for _, file := range files {
if file.IsDir() == true {
continue
}
t.Log(file.Name())
//_,err := c.Add(file.Name())
if err != nil {
t.Log(err)
}
}
}
func TestFile(t *testing.T) {
b, _ := ioutil.ReadFile("./example.json")
t.Log(string(b))
}

View File

@ -1,5 +1,5 @@
{ {
"id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", "id" : "test_id_001",
"target" : { "target" : {
"connection" : { "connection" : {
"ip" : "192.168.1.104", "ip" : "192.168.1.104",