grpc proto file

This commit is contained in:
jackdaw@loafle.com 2017-04-12 20:14:09 +09:00
parent a1a8d24728
commit ec814d7179
3 changed files with 520 additions and 21 deletions

View File

@ -1,20 +1,16 @@
package crawler package crawler
import ( import "errors"
"loafle.com/overflow/of_rpc_go/models/param"
)
type Internal interface { type Internal interface {
Internal(params map[string]interface{}) (param.Output, error) Internal(params map[string]interface{}) ([]byte, error)
} }
type Crawler interface { type Crawler interface {
Init(path string, result *param.Output) error Init(path string) ([]byte,error)
Add(id string, result *param.Output) error Add(id string) ([]byte,error)
Remove(id string, result *param.Output) error Remove(id string) ([]byte,error)
Get(id string, result *param.Output) error Get(id string) ([]byte,error)
} }
type CrawlerImpl struct { type CrawlerImpl struct {
@ -22,35 +18,34 @@ type CrawlerImpl struct {
internal Internal internal Internal
} }
func (c *CrawlerImpl) Init(path string, result *param.Output) error { func (c *CrawlerImpl) Init(path string) ([]byte,error) {
if c.configs == nil { if c.configs == nil {
c.configs = make(map[string]interface{}, 0) c.configs = make(map[string]interface{}, 0)
} }
// load all file in path // load all file in path
return nil return nil,nil
} }
func (c *CrawlerImpl) Add(id string, result *param.Output) error { func (c *CrawlerImpl) Add(id string) ([]byte,error) {
//file load , input config //file load , input config
return nil return nil,nil
} }
func (c *CrawlerImpl) Remove(id string, result *param.Output) error { func (c *CrawlerImpl) Remove(id string) ([]byte,error) {
//remove in config //remove in config
return nil return nil,nil
} }
func (c *CrawlerImpl) Get(id string, result *param.Output) error { func (c *CrawlerImpl) Get(id string)([]byte,error) {
if c.internal != nil { if c.internal != nil {
out, err := c.internal.Internal(c.GetConfig(id)) out, err := c.internal.Internal(c.GetConfig(id))
if err != nil { if err != nil {
//set error fail, message //set error fail, message
return nil,err
} }
return out, nil
*result = out
} }
return nil, errors.New("Not Assign")
return nil
} }
// internal methods // internal methods

445
grpc/grpc.pb.go Normal file
View File

@ -0,0 +1,445 @@
// Code generated by protoc-gen-go.
// source: grpc.proto
// DO NOT EDIT!
/*
Package grpc is a generated protocol buffer package.
It is generated from these files:
grpc.proto
It has these top-level messages:
InputArray
Input
Output
*/
package grpc
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import (
context "golang.org/x/net/context"
grpc1 "google.golang.org/grpc"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type Crawlers int32
const (
Crawlers_HEALTH_ACTIVEDIRECTORY Crawlers = 0
Crawlers_HEALTH_DNS Crawlers = 1
Crawlers_HEALTH_FTP Crawlers = 2
Crawlers_HEALTH_FTPS Crawlers = 3
Crawlers_HEALTH_IMAP Crawlers = 4
Crawlers_HEALTH_LDAP Crawlers = 5
Crawlers_HEALTH_MONGODB Crawlers = 6
Crawlers_HEALTH_MSSQL Crawlers = 7
Crawlers_HEALTH_MYSQL Crawlers = 8
Crawlers_HEALTH_MARIADB Crawlers = 9
Crawlers_HEALTH_PGSQL Crawlers = 10
Crawlers_HEALTH_NETBIOS Crawlers = 11
Crawlers_HEALTH_ORACLE Crawlers = 12
Crawlers_HEALTH_POP3 Crawlers = 13
Crawlers_HEALTH_REDIS Crawlers = 14
Crawlers_HEALTH_RMI Crawlers = 15
Crawlers_HEALTH_SMB Crawlers = 16
Crawlers_HEALTH_SMTP Crawlers = 17
Crawlers_HEALTH_SNMPV2C Crawlers = 18
Crawlers_HEALTH_SNMPV3 Crawlers = 29
Crawlers_HEALTH_SSH Crawlers = 20
Crawlers_HEALTH_TELNET Crawlers = 21
Crawlers_HEALTH_WMI Crawlers = 22
)
var Crawlers_name = map[int32]string{
0: "HEALTH_ACTIVEDIRECTORY",
1: "HEALTH_DNS",
2: "HEALTH_FTP",
3: "HEALTH_FTPS",
4: "HEALTH_IMAP",
5: "HEALTH_LDAP",
6: "HEALTH_MONGODB",
7: "HEALTH_MSSQL",
8: "HEALTH_MYSQL",
9: "HEALTH_MARIADB",
10: "HEALTH_PGSQL",
11: "HEALTH_NETBIOS",
12: "HEALTH_ORACLE",
13: "HEALTH_POP3",
14: "HEALTH_REDIS",
15: "HEALTH_RMI",
16: "HEALTH_SMB",
17: "HEALTH_SMTP",
18: "HEALTH_SNMPV2C",
29: "HEALTH_SNMPV3",
20: "HEALTH_SSH",
21: "HEALTH_TELNET",
22: "HEALTH_WMI",
}
var Crawlers_value = map[string]int32{
"HEALTH_ACTIVEDIRECTORY": 0,
"HEALTH_DNS": 1,
"HEALTH_FTP": 2,
"HEALTH_FTPS": 3,
"HEALTH_IMAP": 4,
"HEALTH_LDAP": 5,
"HEALTH_MONGODB": 6,
"HEALTH_MSSQL": 7,
"HEALTH_MYSQL": 8,
"HEALTH_MARIADB": 9,
"HEALTH_PGSQL": 10,
"HEALTH_NETBIOS": 11,
"HEALTH_ORACLE": 12,
"HEALTH_POP3": 13,
"HEALTH_REDIS": 14,
"HEALTH_RMI": 15,
"HEALTH_SMB": 16,
"HEALTH_SMTP": 17,
"HEALTH_SNMPV2C": 18,
"HEALTH_SNMPV3": 29,
"HEALTH_SSH": 20,
"HEALTH_TELNET": 21,
"HEALTH_WMI": 22,
}
func (x Crawlers) String() string {
return proto.EnumName(Crawlers_name, int32(x))
}
func (Crawlers) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
type InputArray struct {
In []*Input `protobuf:"bytes,1,rep,name=in" json:"in,omitempty"`
}
func (m *InputArray) Reset() { *m = InputArray{} }
func (m *InputArray) String() string { return proto.CompactTextString(m) }
func (*InputArray) ProtoMessage() {}
func (*InputArray) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *InputArray) GetIn() []*Input {
if m != nil {
return m.In
}
return nil
}
type Input struct {
Name Crawlers `protobuf:"varint,1,opt,name=name,enum=Crawlers" json:"name,omitempty"`
Id string `protobuf:"bytes,2,opt,name=id" json:"id,omitempty"`
Path string `protobuf:"bytes,3,opt,name=path" json:"path,omitempty"`
}
func (m *Input) Reset() { *m = Input{} }
func (m *Input) String() string { return proto.CompactTextString(m) }
func (*Input) ProtoMessage() {}
func (*Input) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *Input) GetName() Crawlers {
if m != nil {
return m.Name
}
return Crawlers_HEALTH_ACTIVEDIRECTORY
}
func (m *Input) GetId() string {
if m != nil {
return m.Id
}
return ""
}
func (m *Input) GetPath() string {
if m != nil {
return m.Path
}
return ""
}
// The response message containing the greetings
type Output struct {
StartDate int64 `protobuf:"varint,1,opt,name=startDate" json:"startDate,omitempty"`
EndDate int64 `protobuf:"varint,2,opt,name=endDate" json:"endDate,omitempty"`
Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"`
}
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{2} }
func (m *Output) GetStartDate() int64 {
if m != nil {
return m.StartDate
}
return 0
}
func (m *Output) GetEndDate() int64 {
if m != nil {
return m.EndDate
}
return 0
}
func (m *Output) GetData() []byte {
if m != nil {
return m.Data
}
return nil
}
func init() {
proto.RegisterType((*InputArray)(nil), "InputArray")
proto.RegisterType((*Input)(nil), "Input")
proto.RegisterType((*Output)(nil), "Output")
proto.RegisterEnum("Crawlers", Crawlers_name, Crawlers_value)
}
// Reference imports to suppress errors if they are not otherwise used.
var _ context.Context
var _ grpc1.ClientConn
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
const _ = grpc1.SupportPackageIsVersion3
// Client API for Config service
type ConfigClient interface {
Add(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)
}
type configClient struct {
cc *grpc1.ClientConn
}
func NewConfigClient(cc *grpc1.ClientConn) ConfigClient {
return &configClient{cc}
}
func (c *configClient) Add(ctx context.Context, in *Input, opts ...grpc1.CallOption) (*Output, error) {
out := new(Output)
err := grpc1.Invoke(ctx, "/Config/Add", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *configClient) Remove(ctx context.Context, in *Input, opts ...grpc1.CallOption) (*Output, error) {
out := new(Output)
err := grpc1.Invoke(ctx, "/Config/Remove", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *configClient) Init(ctx context.Context, in *InputArray, opts ...grpc1.CallOption) (*Output, error) {
out := new(Output)
err := grpc1.Invoke(ctx, "/Config/Init", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Config service
type ConfigServer interface {
Add(context.Context, *Input) (*Output, error)
Remove(context.Context, *Input) (*Output, error)
Init(context.Context, *InputArray) (*Output, error)
}
func RegisterConfigServer(s *grpc1.Server, srv ConfigServer) {
s.RegisterService(&_Config_serviceDesc, srv)
}
func _Config_Add_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc1.UnaryServerInterceptor) (interface{}, error) {
in := new(Input)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ConfigServer).Add(ctx, in)
}
info := &grpc1.UnaryServerInfo{
Server: srv,
FullMethod: "/Config/Add",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ConfigServer).Add(ctx, req.(*Input))
}
return interceptor(ctx, in, info, handler)
}
func _Config_Remove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc1.UnaryServerInterceptor) (interface{}, error) {
in := new(Input)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ConfigServer).Remove(ctx, in)
}
info := &grpc1.UnaryServerInfo{
Server: srv,
FullMethod: "/Config/Remove",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ConfigServer).Remove(ctx, req.(*Input))
}
return interceptor(ctx, in, info, handler)
}
func _Config_Init_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc1.UnaryServerInterceptor) (interface{}, error) {
in := new(InputArray)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ConfigServer).Init(ctx, in)
}
info := &grpc1.UnaryServerInfo{
Server: srv,
FullMethod: "/Config/Init",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ConfigServer).Init(ctx, req.(*InputArray))
}
return interceptor(ctx, in, info, handler)
}
var _Config_serviceDesc = grpc1.ServiceDesc{
ServiceName: "Config",
HandlerType: (*ConfigServer)(nil),
Methods: []grpc1.MethodDesc{
{
MethodName: "Add",
Handler: _Config_Add_Handler,
},
{
MethodName: "Remove",
Handler: _Config_Remove_Handler,
},
{
MethodName: "Init",
Handler: _Config_Init_Handler,
},
},
Streams: []grpc1.StreamDesc{},
Metadata: "grpc.proto",
}
// Client API for Data service
type DataClient interface {
Get(ctx context.Context, in *Input, opts ...grpc1.CallOption) (*Output, error)
}
type dataClient struct {
cc *grpc1.ClientConn
}
func NewDataClient(cc *grpc1.ClientConn) DataClient {
return &dataClient{cc}
}
func (c *dataClient) Get(ctx context.Context, in *Input, opts ...grpc1.CallOption) (*Output, error) {
out := new(Output)
err := grpc1.Invoke(ctx, "/Data/Get", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for Data service
type DataServer interface {
Get(context.Context, *Input) (*Output, error)
}
func RegisterDataServer(s *grpc1.Server, srv DataServer) {
s.RegisterService(&_Data_serviceDesc, srv)
}
func _Data_Get_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc1.UnaryServerInterceptor) (interface{}, error) {
in := new(Input)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(DataServer).Get(ctx, in)
}
info := &grpc1.UnaryServerInfo{
Server: srv,
FullMethod: "/Data/Get",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(DataServer).Get(ctx, req.(*Input))
}
return interceptor(ctx, in, info, handler)
}
var _Data_serviceDesc = grpc1.ServiceDesc{
ServiceName: "Data",
HandlerType: (*DataServer)(nil),
Methods: []grpc1.MethodDesc{
{
MethodName: "Get",
Handler: _Data_Get_Handler,
},
},
Streams: []grpc1.StreamDesc{},
Metadata: "grpc.proto",
}
func init() { proto.RegisterFile("grpc.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 449 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x93, 0x5f, 0x6f, 0x9b, 0x30,
0x14, 0xc5, 0x1b, 0xa0, 0xa4, 0xb9, 0x49, 0xe9, 0xad, 0xb5, 0x45, 0xa8, 0x5b, 0xa7, 0x28, 0xda,
0x43, 0xb4, 0x07, 0x1e, 0xc8, 0x27, 0x20, 0xc0, 0x12, 0x4f, 0xfc, 0x9b, 0x8d, 0x3a, 0xf5, 0xa9,
0xf2, 0x06, 0xeb, 0x90, 0x56, 0x12, 0x51, 0x77, 0xd3, 0xbe, 0xd3, 0x3e, 0x64, 0x85, 0x9b, 0x28,
0x7e, 0xe8, 0x9b, 0xcf, 0xef, 0x1c, 0x8e, 0x2f, 0xd2, 0x35, 0xc0, 0x7d, 0xb7, 0xfb, 0xe1, 0xed,
0xba, 0xad, 0xdc, 0xce, 0x3f, 0x02, 0xd0, 0x76, 0xf7, 0x24, 0x83, 0xae, 0x13, 0xff, 0xc8, 0x14,
0x8c, 0xa6, 0x75, 0x07, 0x33, 0x73, 0x31, 0xf6, 0x6d, 0x4f, 0x19, 0xcc, 0x68, 0xda, 0xf9, 0x17,
0x38, 0x55, 0x82, 0x5c, 0x83, 0xd5, 0x8a, 0x87, 0xda, 0x1d, 0xcc, 0x06, 0x0b, 0xc7, 0x1f, 0x79,
0x61, 0x27, 0xfe, 0xfe, 0xae, 0xbb, 0x47, 0xa6, 0x30, 0x71, 0xc0, 0x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 0x3a, 0xda, 0xaf, 0xb2, 0x94, 0xe2, 0x85, 0xa6, 0x79, 0xba, 0x42, 0xd4,
0x2a, 0x78, 0x5a, 0x16, 0x78, 0xa9, 0x5d, 0xcd, 0xb3, 0xb4, 0xb8, 0xf1, 0x43, 0x24, 0xda, 0xd5,
0x8a, 0x2d, 0xf1, 0x5a, 0xef, 0xe1, 0x1b, 0x7c, 0xa3, 0x45, 0xca, 0x38, 0xc9, 0xe2, 0x12, 0xdf,
0x6a, 0x91, 0x6f, 0x29, 0xc5, 0xa9, 0x7f, 0x07, 0x76, 0xb8, 0x6d, 0x7f, 0x36, 0xf7, 0xc4, 0x05,
0x33, 0xa8, 0x2a, 0xb2, 0xdf, 0xb6, 0xab, 0xa1, 0xf7, 0xb2, 0x1c, 0xf3, 0x13, 0xf2, 0x0e, 0x6c,
0x56, 0x3f, 0x6c, 0xff, 0xd4, 0xaf, 0x99, 0x1f, 0xc0, 0xa2, 0x6d, 0x23, 0xc9, 0xd8, 0x3b, 0xae,
0xaf, 0xe6, 0xfb, 0x33, 0xb0, 0x22, 0x21, 0x45, 0x5f, 0xbf, 0xae, 0xe5, 0x2b, 0x0d, 0xdf, 0x6d,
0xf5, 0x00, 0x96, 0xcf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xec, 0xf9, 0x64, 0x26, 0x0e, 0x03, 0x00,
0x00,
}

59
grpc/grpc.proto Normal file
View File

@ -0,0 +1,59 @@
syntax = "proto3";
enum Crawlers {
HEALTH_ACTIVEDIRECTORY = 0;
HEALTH_DNS = 1;
HEALTH_FTP = 2;
HEALTH_FTPS = 3;
HEALTH_IMAP = 4;
HEALTH_LDAP = 5;
HEALTH_MONGODB = 6;
HEALTH_MSSQL = 7;
HEALTH_MYSQL = 8;
HEALTH_MARIADB = 9;
HEALTH_PGSQL = 10;
HEALTH_NETBIOS = 11;
HEALTH_ORACLE = 12;
HEALTH_POP3 = 13;
HEALTH_REDIS = 14;
HEALTH_RMI = 15;
HEALTH_SMB = 16;
HEALTH_SMTP = 17;
HEALTH_SNMPV2C = 18;
HEALTH_SNMPV3 = 29;
HEALTH_SSH = 20;
HEALTH_TELNET = 21;
HEALTH_WMI = 22;
}
// The greeting service definition.
service Config {
rpc Add (Input) returns (Output) {}
rpc Remove (Input) returns (Output) {}
rpc Init (InputArray) returns (Output) {}
}
service Data {
rpc Get (Input) returns (Output) {}
}
// The request message containing the user's name.
message InputArray {
repeated Input in = 1;
}
message Input {
Crawlers name = 1;
string id =2;
string path =3;
}
// The response message containing the greetings
message Output {
int64 startDate = 1;
int64 endDate = 2;
bytes data = 3;
}