diff --git a/crawler.go b/crawler.go index c9fd568..2b67b82 100644 --- a/crawler.go +++ b/crawler.go @@ -3,7 +3,7 @@ package crawler import ( "encoding/json" "errors" - "io/ioutil" + "log" "loafle.com/overflow/crawler_go/config" ) @@ -13,8 +13,8 @@ type Internal interface { } type Crawler interface { - Init(path string) ([]byte, error) - Add(id string) ([]byte, error) + Init(path []byte) ([]byte, error) + Add(data []byte) ([]byte, error) Remove(id string) ([]byte, error) Get(id string) ([]byte, error) } @@ -23,43 +23,29 @@ type CrawlerImpl struct { Crawler configs map[string] config.Config internal Internal - configPath string + } -func (c *CrawlerImpl) Init(path string) ([]byte, error) { +func (c *CrawlerImpl) Init(data []byte) ([]byte, error) { if c.configs == nil { c.configs = make(map[string]config.Config, 0) } - c.configPath = path - files, err := ioutil.ReadDir(c.configPath) + _,err := c.Add(data) + 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 return json.Marshal(true) } -func (c *CrawlerImpl) Add(id string) ([]byte, error) { - - b, err := ioutil.ReadFile(c.configPath + id) - if err != nil { - log.Panic(err) - } - +func (c *CrawlerImpl) Add(data []byte) ([]byte, error) { + var m = config.Config{} - json.Unmarshal(b, &m) - c.configs[id] = m + json.Unmarshal(data, &m) + c.configs[m.Id] = m return json.Marshal(true) } @@ -94,3 +80,5 @@ func (c *CrawlerImpl) PutConfig(name string, m config.Config) { } c.configs[name] = m } + + diff --git a/grpc/grpc.pb.go b/grpc/grpc.pb.go index faab9c7..1bd1352 100644 --- a/grpc/grpc.pb.go +++ b/grpc/grpc.pb.go @@ -14,6 +14,7 @@ It has these top-level messages: InputArray Init Input + InputAdd Output */ package grpc @@ -188,7 +189,7 @@ func (m *InputArray) GetIn() []*Init { type Init struct { 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{} } @@ -203,11 +204,11 @@ func (m *Init) GetName() Crawlers { return Crawlers_HEALTH_ACTIVEDIRECTORY } -func (m *Init) GetPath() string { +func (m *Init) GetData() []byte { if m != nil { - return m.Path + return m.Data } - return "" + return nil } type Input struct { @@ -234,6 +235,30 @@ func (m *Input) GetId() string { 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 type Output struct { 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) String() string { return proto.CompactTextString(m) } 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 { if m != nil { @@ -273,6 +298,7 @@ func init() { proto.RegisterType((*InputArray)(nil), "InputArray") proto.RegisterType((*Init)(nil), "Init") proto.RegisterType((*Input)(nil), "Input") + proto.RegisterType((*InputAdd)(nil), "InputAdd") proto.RegisterType((*Output)(nil), "Output") proto.RegisterEnum("Crawlers", Crawlers_name, Crawlers_value) } @@ -288,7 +314,7 @@ const _ = grpc1.SupportPackageIsVersion4 // Client API for Config service 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) Init(ctx context.Context, in *InputArray, opts ...grpc1.CallOption) (*Output, error) } @@ -301,7 +327,7 @@ func NewConfigClient(cc *grpc1.ClientConn) ConfigClient { 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) err := grpc1.Invoke(ctx, "/Config/Add", in, out, c.cc, opts...) if err != nil { @@ -331,7 +357,7 @@ func (c *configClient) Init(ctx context.Context, in *InputArray, opts ...grpc1.C // Server API for Config service type ConfigServer interface { - Add(context.Context, *Input) (*Output, error) + Add(context.Context, *InputAdd) (*Output, error) Remove(context.Context, *Input) (*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) { - in := new(Input) + in := new(InputAdd) if err := dec(in); err != nil { return nil, err } @@ -353,7 +379,7 @@ func _Config_Add_Handler(srv interface{}, ctx context.Context, dec func(interfac FullMethod: "/Config/Add", } 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) } @@ -546,41 +572,41 @@ var _Status_serviceDesc = grpc1.ServiceDesc{ func init() { proto.RegisterFile("grpc.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 569 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x93, 0x4f, 0x6f, 0x9b, 0x4c, -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c2, 0xcc, 0xf9, 0x8c, 0xea, 0x03, 0x00, 0x00, + // 576 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x54, 0x4d, 0x6f, 0xd3, 0x40, + 0x10, 0x6d, 0x6c, 0xc7, 0x4e, 0x26, 0x6d, 0x3a, 0x1d, 0xda, 0x12, 0xd2, 0x0f, 0x22, 0x23, 0xa1, + 0x8a, 0x83, 0x0f, 0xa9, 0x84, 0xc4, 0x81, 0x83, 0x63, 0x9b, 0xc6, 0x28, 0x8e, 0xcd, 0xae, 0x55, + 0xe8, 0x09, 0xb9, 0x8d, 0x29, 0x11, 0xad, 0x13, 0xb9, 0x1b, 0x50, 0xff, 0x05, 0x3f, 0x19, 0xf9, + 0x23, 0xcd, 0x1e, 0x90, 0x90, 0xb8, 0xcd, 0x7b, 0x6f, 0xf6, 0xbd, 0x5d, 0x7b, 0x77, 0x00, 0x6e, + 0xf3, 0xe5, 0x8d, 0xb5, 0xcc, 0x17, 0x62, 0x61, 0x1a, 0xd0, 0xf4, 0xee, 0x97, 0xe2, 0xd1, 0x7c, + 0x09, 0xc6, 0x68, 0xb1, 0xb8, 0x4b, 0x93, 0x8c, 0xf6, 0xa1, 0x79, 0xf3, 0x3d, 0xbd, 0xf9, 0xd1, + 0x6b, 0x0c, 0x1a, 0x67, 0x2d, 0x56, 0x01, 0xf3, 0x15, 0x80, 0x9f, 0x2d, 0x57, 0xc2, 0xce, 0xf3, + 0xe4, 0x91, 0x0e, 0x40, 0x99, 0x67, 0xbd, 0xc6, 0x40, 0x3d, 0xeb, 0x0c, 0x9b, 0x96, 0x9f, 0xcd, + 0x05, 0x53, 0xe6, 0x99, 0xf9, 0x0e, 0xb4, 0xa2, 0xa6, 0x13, 0xd0, 0xb2, 0xe4, 0x3e, 0x2d, 0x1d, + 0xba, 0xc3, 0xb6, 0xe5, 0xe4, 0xc9, 0xaf, 0xbb, 0x34, 0x7f, 0x60, 0x25, 0x4d, 0x04, 0xda, 0x2c, + 0x11, 0x49, 0x4f, 0x19, 0x34, 0xce, 0xb6, 0x59, 0x59, 0x9b, 0x6f, 0xa1, 0x59, 0xfa, 0xff, 0x6b, + 0x6d, 0x17, 0x94, 0xf9, 0xac, 0x5c, 0xd9, 0x66, 0xca, 0x7c, 0x66, 0xbe, 0x87, 0x56, 0xb5, 0xaf, + 0xd9, 0xec, 0x7f, 0x62, 0x63, 0xd0, 0xc3, 0x95, 0x28, 0x72, 0x8f, 0xa1, 0xfd, 0x20, 0x92, 0x5c, + 0xb8, 0x89, 0xa8, 0x1c, 0x54, 0xb6, 0x21, 0xa8, 0x07, 0x46, 0x9a, 0xcd, 0x4a, 0x4d, 0x29, 0xb5, + 0x35, 0x7c, 0x72, 0x55, 0x37, 0xae, 0x6f, 0x7e, 0x6b, 0xd0, 0x5a, 0x87, 0x53, 0x1f, 0x0e, 0xc7, + 0x9e, 0x3d, 0x89, 0xc7, 0x5f, 0x6d, 0x27, 0xf6, 0x2f, 0x3d, 0xd7, 0x67, 0x9e, 0x13, 0x87, 0xec, + 0x0a, 0xb7, 0xa8, 0x0b, 0x50, 0x6b, 0xee, 0x94, 0x63, 0x43, 0xc2, 0x1f, 0xe2, 0x08, 0x15, 0xda, + 0x85, 0xce, 0x06, 0x73, 0x54, 0x25, 0xc2, 0x0f, 0xec, 0x08, 0x35, 0x89, 0x98, 0xb8, 0x76, 0x84, + 0x4d, 0x22, 0xe8, 0xd6, 0x44, 0x10, 0x4e, 0x2f, 0x42, 0x77, 0x84, 0x3a, 0x21, 0x6c, 0xaf, 0x39, + 0xce, 0x3f, 0x4d, 0xd0, 0x90, 0x99, 0xab, 0x82, 0x69, 0xc9, 0xeb, 0x6c, 0xe6, 0xdb, 0xee, 0x08, + 0xdb, 0x52, 0x57, 0x74, 0x51, 0x74, 0x81, 0xd4, 0x35, 0xf5, 0xe2, 0x91, 0x1f, 0x72, 0xec, 0xd0, + 0x1e, 0xec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x17, 0x87, 0xe1, 0x6b, 0xd0, 0xb9, 0x48, 0xc4, 0xea, 0x81, + 0x8e, 0x9f, 0x2a, 0xdd, 0x2a, 0x47, 0x40, 0xbf, 0x65, 0xd5, 0x13, 0xc0, 0xdc, 0xba, 0xd6, 0xcb, + 0xf1, 0x70, 0xfe, 0x27, 0x00, 0x00, 0xff, 0xff, 0xe6, 0x5f, 0x44, 0x44, 0x2c, 0x04, 0x00, 0x00, } diff --git a/grpc/grpc.proto b/grpc/grpc.proto index 417a7d8..b61ef32 100644 --- a/grpc/grpc.proto +++ b/grpc/grpc.proto @@ -37,7 +37,7 @@ enum Crawlers { // services service Config { - rpc Add (Input) returns (Output) {} + rpc Add (InputAdd) returns (Output) {} rpc Remove (Input) returns (Output) {} rpc Init (InputArray) returns (Output) {} } @@ -62,7 +62,7 @@ message InputArray { message Init { Crawlers name = 1; - string path = 2; + bytes data = 2; } message Input { @@ -70,6 +70,11 @@ message Input { string id =2; } +message InputAdd { + Crawlers name = 1; + bytes data =2; +} + // response models message Output { int64 startDate = 1; diff --git a/test/crawler_test.go b/test/crawler_test.go index fcd650e..ae6b799 100644 --- a/test/crawler_test.go +++ b/test/crawler_test.go @@ -6,13 +6,17 @@ import ( "encoding/json" "loafle.com/overflow/crawler_go/health_crawler/redis_protocol_crawler_go" "loafle.com/overflow/crawler_go" - + + "io/ioutil" ) func initConfig() crawler.CrawlerImpl{ c := crawler.CrawlerImpl{} c.SetInternal(redis_protocol_crawler_go.NewRedisHeahthCrawler()) - c.Init("./") + + b, _ := ioutil.ReadFile("./example.json") + + c.Init(b) return c } @@ -20,27 +24,28 @@ func initConfig() crawler.CrawlerImpl{ func TestCrawlerInit(t *testing.T) { c := initConfig() - m := c.GetConfig("example.json") - assert.Equal(t, m.Id , "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734") + m := c.GetConfig("test_id_001") + assert.Equal(t, m.Id , "test_id_001") } func TestCrawlerAdd(t *testing.T) { c := initConfig() - c.Remove("example.json") - b , _ := c.Add("example.json") - + c.Remove("test_id_001") + bb, _ := ioutil.ReadFile("./example.json") + b , _ := c.Add(bb) + var ck bool json.Unmarshal(b,&ck) - + assert.Equal(t,true,ck) } func TestCrawlerRemove(t *testing.T) { c := initConfig() - b, _ := c.Remove("example.json") + b, _ := c.Remove("test_id_001") var ck bool json.Unmarshal(b,&ck) @@ -50,7 +55,7 @@ func TestCrawlerRemove(t *testing.T) { func TestCrawlerGet(t *testing.T) { c := initConfig() - b, _ := c.Get("example.json") + b, _ := c.Get("test_id_001") var ck bool 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)) + +} diff --git a/test/example.json b/test/example.json index 3cf0a7c..ae45668 100644 --- a/test/example.json +++ b/test/example.json @@ -1,5 +1,5 @@ { - "id" : "SOEJWEOJWOEJOSDJFOASDJFOSDFO2903870928734", + "id" : "test_id_001", "target" : { "connection" : { "ip" : "192.168.1.104",