From 2d528463d2db99905d557d708bbf1498c293d67c Mon Sep 17 00:00:00 2001 From: UnicodingUnicorn <7555ic@gmail.com> Date: Sat, 16 Feb 2019 12:49:48 +0800 Subject: [PATCH] Initial commit --- .gitignore | 12 ++ README.md | 90 ++++++++++++++- bite.pb.go | 103 +++++++++++++++++ client.pb.go | 84 ++++++++++++++ data_request.pb.go | 94 +++++++++++++++ main.go | 276 +++++++++++++++++++++++++++++++++++++++++++++ response.pb.go | 95 ++++++++++++++++ scan_request.pb.go | 103 +++++++++++++++++ store.pb.go | 85 ++++++++++++++ 9 files changed, 941 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 bite.pb.go create mode 100644 client.pb.go create mode 100644 data_request.pb.go create mode 100644 main.go create mode 100644 response.pb.go create mode 100644 scan_request.pb.go create mode 100644 store.pb.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2dd955 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out diff --git a/README.md b/README.md index 220f7ce..d3e4290 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,91 @@ # backend-transcription -Beep backend handling transcription of bites to text via Google Cloud. \ No newline at end of file +Beep backend handling transcription of bites to text via Google Cloud. + +## Quickstart + +``` +go build && ./backend-transcription +``` + +## Flags + +Flags are supplied to the compiled go program in the form ```-flag=stuff```. + +| Flag | Description | Default | +| ---- | ----------- | ------- | +| listen | Port number to listen on | 8080 | +| nats | URL of NATS | nats://localhost:4222 | +| api-key | Google Cloud API key | Something that works. Probably | + +## API + +## Scan Bites + +``` +GET /conversation/:key/scan +``` + +Get a list of transcription start times within a conversation key and specified timespan. + +#### URL Params + +| Name | Type | Description | +| ---- | ---- | ----------- | +| key | String | Audio transcription's bite's conversation's ID. | + +#### Querystring + +| Name | Type | Description | +| ---- | ---- | ----------- | +| from | Epoch timestamp | Time to start scanning from | +| to | Epoch timestamp | Time to scan to | + +#### Success (200 OK) + +``` +Content-Type: application/json +``` + +``` +{ + "previous": >, + "starts": [Timestamp, Timestamp...], + "next": >, +} +``` + +#### Errors + +| Code | Description | +| ---- | ----------- | +| 400 | Malformed input (from/to not timestamp, key not alphanumeric). | +| 500 | NATs or protobuf serialisation encountered errors. | + +--- + +### Get Bite + +``` +GET /conversation/:key/start/:start +``` + +Get a specific ```transcription```. + +#### URL Params + +| Name | Type | Description | +| ---- | ---- | ----------- | +| key | String | Audio transcription's conversation's ID. | +| start | Epoch timestamp | Time the audio transcription starts. | + +#### Success (200 OK) + +Plaintext transcription + +#### Errors + +| Code | Description | +| ---- | ----------- | +| 400 | start is not an uint/key is not an alphanumeric string/specified bite could not be found | +| 500 | NATs or protobuf serialisation encountered errors. | diff --git a/bite.pb.go b/bite.pb.go new file mode 100644 index 0000000..2a884ce --- /dev/null +++ b/bite.pb.go @@ -0,0 +1,103 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: bite.proto + +package main + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// 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.ProtoPackageIsVersion3 // please upgrade the proto package + +type Bite struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Start uint64 `protobuf:"varint,2,opt,name=start,proto3" json:"start,omitempty"` + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` + Client *Client `protobuf:"bytes,4,opt,name=client,proto3" json:"client,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Bite) Reset() { *m = Bite{} } +func (m *Bite) String() string { return proto.CompactTextString(m) } +func (*Bite) ProtoMessage() {} +func (*Bite) Descriptor() ([]byte, []int) { + return fileDescriptor_e1ec993646b17549, []int{0} +} + +func (m *Bite) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Bite.Unmarshal(m, b) +} +func (m *Bite) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Bite.Marshal(b, m, deterministic) +} +func (m *Bite) XXX_Merge(src proto.Message) { + xxx_messageInfo_Bite.Merge(m, src) +} +func (m *Bite) XXX_Size() int { + return xxx_messageInfo_Bite.Size(m) +} +func (m *Bite) XXX_DiscardUnknown() { + xxx_messageInfo_Bite.DiscardUnknown(m) +} + +var xxx_messageInfo_Bite proto.InternalMessageInfo + +func (m *Bite) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *Bite) GetStart() uint64 { + if m != nil { + return m.Start + } + return 0 +} + +func (m *Bite) GetData() []byte { + if m != nil { + return m.Data + } + return nil +} + +func (m *Bite) GetClient() *Client { + if m != nil { + return m.Client + } + return nil +} + +func init() { + proto.RegisterType((*Bite)(nil), "main.Bite") +} + +func init() { proto.RegisterFile("bite.proto", fileDescriptor_e1ec993646b17549) } + +var fileDescriptor_e1ec993646b17549 = []byte{ + // 139 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4a, 0xca, 0x2c, 0x49, + 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, 0x93, 0xe2, 0x49, 0xce, + 0xc9, 0x4c, 0xcd, 0x2b, 0x81, 0x88, 0x29, 0x65, 0x70, 0xb1, 0x38, 0x65, 0x96, 0xa4, 0x0a, 0x09, + 0x70, 0x31, 0x67, 0xa7, 0x56, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x81, 0x98, 0x42, 0x22, + 0x5c, 0xac, 0xc5, 0x25, 0x89, 0x45, 0x25, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0x2c, 0x41, 0x10, 0x8e, + 0x90, 0x10, 0x17, 0x4b, 0x4a, 0x62, 0x49, 0xa2, 0x04, 0xb3, 0x02, 0xa3, 0x06, 0x4f, 0x10, 0x98, + 0x2d, 0xa4, 0xc2, 0xc5, 0x06, 0x31, 0x53, 0x82, 0x45, 0x81, 0x51, 0x83, 0xdb, 0x88, 0x47, 0x0f, + 0x64, 0x91, 0x9e, 0x33, 0x58, 0x2c, 0x08, 0x2a, 0x97, 0xc4, 0x06, 0xb6, 0xd0, 0x18, 0x10, 0x00, + 0x00, 0xff, 0xff, 0x0a, 0x85, 0x92, 0x1b, 0x92, 0x00, 0x00, 0x00, +} diff --git a/client.pb.go b/client.pb.go new file mode 100644 index 0000000..b968e65 --- /dev/null +++ b/client.pb.go @@ -0,0 +1,84 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: client.proto + +package main + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// 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.ProtoPackageIsVersion3 // please upgrade the proto package + +type Client struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Client string `protobuf:"bytes,2,opt,name=client,proto3" json:"client,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Client) Reset() { *m = Client{} } +func (m *Client) String() string { return proto.CompactTextString(m) } +func (*Client) ProtoMessage() {} +func (*Client) Descriptor() ([]byte, []int) { + return fileDescriptor_014de31d7ac8c57c, []int{0} +} + +func (m *Client) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Client.Unmarshal(m, b) +} +func (m *Client) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Client.Marshal(b, m, deterministic) +} +func (m *Client) XXX_Merge(src proto.Message) { + xxx_messageInfo_Client.Merge(m, src) +} +func (m *Client) XXX_Size() int { + return xxx_messageInfo_Client.Size(m) +} +func (m *Client) XXX_DiscardUnknown() { + xxx_messageInfo_Client.DiscardUnknown(m) +} + +var xxx_messageInfo_Client proto.InternalMessageInfo + +func (m *Client) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *Client) GetClient() string { + if m != nil { + return m.Client + } + return "" +} + +func init() { + proto.RegisterType((*Client)(nil), "main.Client") +} + +func init() { proto.RegisterFile("client.proto", fileDescriptor_014de31d7ac8c57c) } + +var fileDescriptor_014de31d7ac8c57c = []byte{ + // 83 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0xce, 0xc9, 0x4c, + 0xcd, 0x2b, 0xd1, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, 0x53, 0x32, + 0xe2, 0x62, 0x73, 0x06, 0x8b, 0x0a, 0x09, 0x70, 0x31, 0x67, 0xa7, 0x56, 0x4a, 0x30, 0x2a, 0x30, + 0x6a, 0x70, 0x06, 0x81, 0x98, 0x42, 0x62, 0x5c, 0x6c, 0x10, 0x1d, 0x12, 0x4c, 0x60, 0x41, 0x28, + 0x2f, 0x89, 0x0d, 0x6c, 0x80, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x95, 0x71, 0x3f, 0xbd, 0x50, + 0x00, 0x00, 0x00, +} diff --git a/data_request.pb.go b/data_request.pb.go new file mode 100644 index 0000000..858132e --- /dev/null +++ b/data_request.pb.go @@ -0,0 +1,94 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: store/data_request.proto + +package main + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// 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.ProtoPackageIsVersion3 // please upgrade the proto package + +type DataRequest struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Start uint64 `protobuf:"varint,2,opt,name=start,proto3" json:"start,omitempty"` + Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DataRequest) Reset() { *m = DataRequest{} } +func (m *DataRequest) String() string { return proto.CompactTextString(m) } +func (*DataRequest) ProtoMessage() {} +func (*DataRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_1c7f2c7bfa43f02c, []int{0} +} + +func (m *DataRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DataRequest.Unmarshal(m, b) +} +func (m *DataRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DataRequest.Marshal(b, m, deterministic) +} +func (m *DataRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DataRequest.Merge(m, src) +} +func (m *DataRequest) XXX_Size() int { + return xxx_messageInfo_DataRequest.Size(m) +} +func (m *DataRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DataRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DataRequest proto.InternalMessageInfo + +func (m *DataRequest) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *DataRequest) GetStart() uint64 { + if m != nil { + return m.Start + } + return 0 +} + +func (m *DataRequest) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func init() { + proto.RegisterType((*DataRequest)(nil), "main.DataRequest") +} + +func init() { proto.RegisterFile("store/data_request.proto", fileDescriptor_1c7f2c7bfa43f02c) } + +var fileDescriptor_1c7f2c7bfa43f02c = []byte{ + // 119 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x28, 0x2e, 0xc9, 0x2f, + 0x4a, 0xd5, 0x4f, 0x49, 0x2c, 0x49, 0x8c, 0x2f, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0xd1, 0x2b, + 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, 0x53, 0xf2, 0xe4, 0xe2, 0x76, 0x49, + 0x2c, 0x49, 0x0c, 0x82, 0x48, 0x09, 0x09, 0x70, 0x31, 0x67, 0xa7, 0x56, 0x4a, 0x30, 0x2a, 0x30, + 0x6a, 0x70, 0x06, 0x81, 0x98, 0x42, 0x22, 0x5c, 0xac, 0xc5, 0x25, 0x89, 0x45, 0x25, 0x12, 0x4c, + 0x0a, 0x8c, 0x1a, 0x2c, 0x41, 0x10, 0x8e, 0x90, 0x10, 0x17, 0x4b, 0x49, 0x65, 0x41, 0xaa, 0x04, + 0x33, 0x58, 0x21, 0x98, 0x9d, 0xc4, 0x06, 0x36, 0xd7, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x70, + 0x54, 0xb9, 0xcc, 0x73, 0x00, 0x00, 0x00, +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..c07d45f --- /dev/null +++ b/main.go @@ -0,0 +1,276 @@ +package main; + +import ( + "bytes" + "encoding/base64" + "encoding/json" + "flag" + "io/ioutil" + "log" + "net/http" + "strconv" + "time" + + "github.com/golang/protobuf/proto" + "github.com/julienschmidt/httprouter" + "github.com/nats-io/go-nats" +) + +var listen string +var apiKey string +var natsHost string + +var nc *nats.Conn + +type AudioOptions struct { + Content []byte `json:"content"` +} + +type AudioConfigOptions struct { + LanguageCode string `json:"languageCode"` +} + +type AudioConfig struct { + Audio AudioOptions `json:"audio"` + Config AudioConfigOptions `json:"config"` +} + +type AudioTranscript struct { + Transcript string `json:"transcript"` + Confidence float32 `json:"confidence"` +} + +type AudioResult struct { + Alternatives []AudioTranscript `json:"alternatives"` +} + +type AudioResults struct { + Results []AudioResult `json:"results"` +} + +func main() { + // Parse flags + flag.StringVar(&listen, "listen", ":8080", "host and port to listen on") + flag.StringVar(&apiKey, "api-key", "AIzaSyDxSXDefzw9gXCQaVzOCYlRn_vcC9Da9Q0", "Google Cloud API key") + flag.StringVar(&natsHost, "nats", "nats://localhost:4222", "host and port of NATS") + flag.Parse() + + //NATS + nc, err := nats.Connect(natsHost) + if err != nil { + log.Fatal(err) + return + } + + nc.Subscribe("new_bite", NewBite) + + // Routes + router := httprouter.New() + + router.GET("/transcription/:key/scan", ScanTranscription) // Scanning + router.GET("/transcription/:key/start/:start", GetTranscription) + + // Start server + log.Printf("starting server on %s", listen) + log.Fatal(http.ListenAndServe(listen, router)) +} + +func NewBite(m *nats.Msg) { + bite := Bite{} + if err := proto.Unmarshal(m.Data, &bite); err != nil { + log.Println(err) + return + } + + //TODO: Check cache (store) for existing transcription + + // Base64 encode audio bytes + audioEncoded := base64.StdEncoding.EncodeToString(bite.Data) + + config := AudioConfig { + Audio: AudioOptions { + Content: []byte(audioEncoded), + }, + Config: AudioConfigOptions { + LanguageCode: "en-US", + }, + } + + configJson, err := json.Marshal(config) + if err != nil { + log.Println(err) + return + } + + url := "https://speech.googleapis.com/v1/speech:recognize?key=" + apiKey + req, err := http.NewRequest("POST", url, bytes.NewBuffer(configJson)) + req.Header.Set("Content-Type", "application/json") + + client := http.Client{} + resp, err := client.Do(req) + if err != nil { + log.Println(err) + errRes := Response { + Code: 500, + Message: []byte(http.StatusText(http.StatusInternalServerError)), + Client: bite.Client, + } + errResBytes, err := proto.Marshal(&errRes) + if err == nil { + nc.Publish("res", errResBytes) + } + return + } + + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + log.Println(err) + errRes := Response { + Code: 500, + Message: []byte(http.StatusText(http.StatusInternalServerError)), + Client: bite.Client, + } + errResBytes, err := proto.Marshal(&errRes) + if err == nil { + nc.Publish("res", errResBytes) + } + return + } + + results := AudioResults{} + err = json.Unmarshal(body, &results) + if err != nil { + log.Println(err) + errRes := Response { + Code: 500, + Message: []byte(http.StatusText(http.StatusInternalServerError)), + Client: bite.Client, + } + errResBytes, err := proto.Marshal(&errRes) + if err == nil { + nc.Publish("res", errResBytes) + } + return + } + + if len(results.Results) > 0 && len(results.Results[0].Alternatives) > 0 { + bite.Data = []byte(results.Results[0].Alternatives[0].Transcript) + + storeRequest := Store { + Type: "transcription", + Bite: &bite, + } + storeRequestBytes, err := proto.Marshal(&storeRequest) + if err != nil { + return + } + + nc.Publish("new_store", storeRequestBytes) + } else { + // 404 + errRes := Response { + Code: 404, + Message: []byte(http.StatusText(http.StatusNotFound)), + Client: bite.Client, + } + errResBytes, err := proto.Marshal(&errRes) + if err == nil { + nc.Publish("res", errResBytes) + } + } +} + +// Route handlers +func ParseStartString(start string) (uint64, error) { + return strconv.ParseUint(start, 10, 64) +} + +func ScanTranscription(w http.ResponseWriter, r *http.Request, p httprouter.Params) { + from, err := ParseStartString(r.FormValue("from")) + if err != nil { + http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) + return + } + to, err := ParseStartString(r.FormValue("to")) + if err != nil { + http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) + return + } + + scanRequest := ScanRequest { + Key: p.ByName("key"), + From: from, + To: to, + Type: "transcription", + } + + drBytes, err := proto.Marshal(&scanRequest); + if err != nil { + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + + msg, err := nc.Request("scan_store", drBytes, 10 * time.Second) // 10s timeout + if err != nil { + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + + res := Response {} + if err := proto.Unmarshal(msg.Data, &res); err != nil { + log.Println(err) + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + + if res.Code == 200 { + w.Header().Set("Content-Type", "application/json") + w.Write(res.Message) + } else if len(res.Message) == 0 { + http.Error(w, http.StatusText(int(res.Code)), int(res.Code)) + } else { + http.Error(w, string(res.Message), int(res.Code)) + } +} + +func GetTranscription(w http.ResponseWriter, r *http.Request, p httprouter.Params) { + start, err := ParseStartString(p.ByName("start")) + if err != nil { + http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) + return + } + + dataRequest := DataRequest { + Key: p.ByName("key"), + Start: start, + Type: "transcription", + } + + drBytes, err := proto.Marshal(&dataRequest); + if err != nil { + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + + msg, err := nc.Request("request_store", drBytes, 10 * time.Second) // 10s timeout + if err != nil { + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + + res := Response {} + if err := proto.Unmarshal(msg.Data, &res); err != nil { + log.Println(err) + http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) + return + } + + if res.Code == 200 { + w.Header().Add("Content-Type", "text/plain") + w.Write(res.Message) + } else if len(res.Message) == 0 { + http.Error(w, http.StatusText(int(res.Code)), int(res.Code)) + } else { + http.Error(w, string(res.Message), int(res.Code)) + } +} diff --git a/response.pb.go b/response.pb.go new file mode 100644 index 0000000..3797a39 --- /dev/null +++ b/response.pb.go @@ -0,0 +1,95 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: response.proto + +package main + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// 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.ProtoPackageIsVersion3 // please upgrade the proto package + +type Response struct { + Code uint32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"` + Message []byte `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + Client *Client `protobuf:"bytes,3,opt,name=client,proto3" json:"client,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Response) Reset() { *m = Response{} } +func (m *Response) String() string { return proto.CompactTextString(m) } +func (*Response) ProtoMessage() {} +func (*Response) Descriptor() ([]byte, []int) { + return fileDescriptor_0fbc901015fa5021, []int{0} +} + +func (m *Response) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Response.Unmarshal(m, b) +} +func (m *Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Response.Marshal(b, m, deterministic) +} +func (m *Response) XXX_Merge(src proto.Message) { + xxx_messageInfo_Response.Merge(m, src) +} +func (m *Response) XXX_Size() int { + return xxx_messageInfo_Response.Size(m) +} +func (m *Response) XXX_DiscardUnknown() { + xxx_messageInfo_Response.DiscardUnknown(m) +} + +var xxx_messageInfo_Response proto.InternalMessageInfo + +func (m *Response) GetCode() uint32 { + if m != nil { + return m.Code + } + return 0 +} + +func (m *Response) GetMessage() []byte { + if m != nil { + return m.Message + } + return nil +} + +func (m *Response) GetClient() *Client { + if m != nil { + return m.Client + } + return nil +} + +func init() { + proto.RegisterType((*Response)(nil), "main.Response") +} + +func init() { proto.RegisterFile("response.proto", fileDescriptor_0fbc901015fa5021) } + +var fileDescriptor_0fbc901015fa5021 = []byte{ + // 129 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2b, 0x4a, 0x2d, 0x2e, + 0xc8, 0xcf, 0x2b, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, + 0x93, 0xe2, 0x49, 0xce, 0xc9, 0x4c, 0xcd, 0x2b, 0x81, 0x88, 0x29, 0xc5, 0x71, 0x71, 0x04, 0x41, + 0x55, 0x09, 0x09, 0x71, 0xb1, 0x24, 0xe7, 0xa7, 0xa4, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0xf0, 0x06, + 0x81, 0xd9, 0x42, 0x12, 0x5c, 0xec, 0xb9, 0xa9, 0xc5, 0xc5, 0x89, 0xe9, 0xa9, 0x12, 0x4c, 0x0a, + 0x8c, 0x1a, 0x3c, 0x41, 0x30, 0xae, 0x90, 0x0a, 0x17, 0x1b, 0xc4, 0x24, 0x09, 0x66, 0x05, 0x46, + 0x0d, 0x6e, 0x23, 0x1e, 0x3d, 0x90, 0xf1, 0x7a, 0xce, 0x60, 0xb1, 0x20, 0xa8, 0x5c, 0x12, 0x1b, + 0xd8, 0x1a, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x14, 0x8c, 0xe3, 0xa3, 0x8c, 0x00, 0x00, + 0x00, +} diff --git a/scan_request.pb.go b/scan_request.pb.go new file mode 100644 index 0000000..681c08e --- /dev/null +++ b/scan_request.pb.go @@ -0,0 +1,103 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: store/scan_request.proto + +package main + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// 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.ProtoPackageIsVersion3 // please upgrade the proto package + +type ScanRequest struct { + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + From uint64 `protobuf:"varint,2,opt,name=from,proto3" json:"from,omitempty"` + To uint64 `protobuf:"varint,3,opt,name=to,proto3" json:"to,omitempty"` + Type string `protobuf:"bytes,4,opt,name=type,proto3" json:"type,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ScanRequest) Reset() { *m = ScanRequest{} } +func (m *ScanRequest) String() string { return proto.CompactTextString(m) } +func (*ScanRequest) ProtoMessage() {} +func (*ScanRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_812dc305bd560f72, []int{0} +} + +func (m *ScanRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ScanRequest.Unmarshal(m, b) +} +func (m *ScanRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ScanRequest.Marshal(b, m, deterministic) +} +func (m *ScanRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_ScanRequest.Merge(m, src) +} +func (m *ScanRequest) XXX_Size() int { + return xxx_messageInfo_ScanRequest.Size(m) +} +func (m *ScanRequest) XXX_DiscardUnknown() { + xxx_messageInfo_ScanRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_ScanRequest proto.InternalMessageInfo + +func (m *ScanRequest) GetKey() string { + if m != nil { + return m.Key + } + return "" +} + +func (m *ScanRequest) GetFrom() uint64 { + if m != nil { + return m.From + } + return 0 +} + +func (m *ScanRequest) GetTo() uint64 { + if m != nil { + return m.To + } + return 0 +} + +func (m *ScanRequest) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func init() { + proto.RegisterType((*ScanRequest)(nil), "main.ScanRequest") +} + +func init() { proto.RegisterFile("store/scan_request.proto", fileDescriptor_812dc305bd560f72) } + +var fileDescriptor_812dc305bd560f72 = []byte{ + // 129 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x28, 0x2e, 0xc9, 0x2f, + 0x4a, 0xd5, 0x2f, 0x4e, 0x4e, 0xcc, 0x8b, 0x2f, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0xd1, 0x2b, + 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, 0x53, 0x0a, 0xe7, 0xe2, 0x0e, 0x4e, + 0x4e, 0xcc, 0x0b, 0x82, 0x48, 0x09, 0x09, 0x70, 0x31, 0x67, 0xa7, 0x56, 0x4a, 0x30, 0x2a, 0x30, + 0x6a, 0x70, 0x06, 0x81, 0x98, 0x42, 0x42, 0x5c, 0x2c, 0x69, 0x45, 0xf9, 0xb9, 0x12, 0x4c, 0x0a, + 0x8c, 0x1a, 0x2c, 0x41, 0x60, 0xb6, 0x10, 0x1f, 0x17, 0x53, 0x49, 0xbe, 0x04, 0x33, 0x58, 0x84, + 0xa9, 0x24, 0x1f, 0xa4, 0xa6, 0xa4, 0xb2, 0x20, 0x55, 0x82, 0x05, 0xac, 0x0d, 0xcc, 0x4e, 0x62, + 0x03, 0xdb, 0x62, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0x2e, 0x77, 0x60, 0x56, 0x81, 0x00, 0x00, + 0x00, +} diff --git a/store.pb.go b/store.pb.go new file mode 100644 index 0000000..e6463cc --- /dev/null +++ b/store.pb.go @@ -0,0 +1,85 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: store.proto + +package main + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +// 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.ProtoPackageIsVersion3 // please upgrade the proto package + +type Store struct { + Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` + Bite *Bite `protobuf:"bytes,2,opt,name=bite,proto3" json:"bite,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Store) Reset() { *m = Store{} } +func (m *Store) String() string { return proto.CompactTextString(m) } +func (*Store) ProtoMessage() {} +func (*Store) Descriptor() ([]byte, []int) { + return fileDescriptor_98bbca36ef968dfc, []int{0} +} + +func (m *Store) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Store.Unmarshal(m, b) +} +func (m *Store) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Store.Marshal(b, m, deterministic) +} +func (m *Store) XXX_Merge(src proto.Message) { + xxx_messageInfo_Store.Merge(m, src) +} +func (m *Store) XXX_Size() int { + return xxx_messageInfo_Store.Size(m) +} +func (m *Store) XXX_DiscardUnknown() { + xxx_messageInfo_Store.DiscardUnknown(m) +} + +var xxx_messageInfo_Store proto.InternalMessageInfo + +func (m *Store) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *Store) GetBite() *Bite { + if m != nil { + return m.Bite + } + return nil +} + +func init() { + proto.RegisterType((*Store)(nil), "main.Store") +} + +func init() { proto.RegisterFile("store.proto", fileDescriptor_98bbca36ef968dfc) } + +var fileDescriptor_98bbca36ef968dfc = []byte{ + // 104 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2e, 0x2e, 0xc9, 0x2f, + 0x4a, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0xc9, 0x4d, 0xcc, 0xcc, 0x93, 0xe2, 0x4a, + 0xca, 0x2c, 0x81, 0x8a, 0x28, 0x59, 0x73, 0xb1, 0x06, 0x83, 0x14, 0x08, 0x09, 0x71, 0xb1, 0x94, + 0x54, 0x16, 0xa4, 0x4a, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x81, 0xd9, 0x42, 0x72, 0x5c, 0x2c, + 0x20, 0xa5, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xdc, 0x46, 0x5c, 0x7a, 0x20, 0xdd, 0x7a, 0x4e, 0x99, + 0x25, 0xa9, 0x41, 0x60, 0xf1, 0x24, 0x36, 0xb0, 0x19, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x84, 0x05, 0xf9, 0x1a, 0x64, 0x00, 0x00, 0x00, +}