Added integration with backend-subscribe
parent
fa145f7948
commit
7886168592
11
README.md
11
README.md
|
@ -15,3 +15,14 @@ Refer to protobuf definitions in ```backend-protobuf```.
|
|||
| new_store | Publish to | Store | - | - | - |
|
||||
| request_store | Request | DataRequest | - | Response | client |
|
||||
| scan_store | Request | ScanRequest | - | Response | client |
|
||||
|
||||
|
||||
### new_store
|
||||
|
||||
Pushes the results of its operation to ```backend-subscribe```.
|
||||
|
||||
| Code | Message | Description |
|
||||
| ---- | ------- | ----------- |
|
||||
| 200 | Inserted bite's key | Store operation was successful |
|
||||
| 400 | 400 Bad Request | Key could not be marshalled properly |
|
||||
| 500 | 500 Internal Server Error | Error storing the bite in badger |
|
||||
|
|
30
main.go
30
main.go
|
@ -52,13 +52,22 @@ func main() {
|
|||
func NewStore(m *nats.Msg) {
|
||||
storeRequest := Store{}
|
||||
if err := proto.Unmarshal(m.Data, &storeRequest); err != nil {
|
||||
log.Println(err)
|
||||
log.Println(err) // Fail quietly since protobuf data is needed torespond
|
||||
return
|
||||
}
|
||||
|
||||
key, err := MarshalKey(storeRequest.Type, storeRequest.Bite.Key, storeRequest.Bite.Start)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
errRes := Response {
|
||||
Code: 400,
|
||||
Message: http.StatusText(http.StatusBadRequest),
|
||||
Client: storeRequest.Bite.Client,
|
||||
}
|
||||
errResBytes, errResErr := proto.Marshal(&errRes)
|
||||
if errResErr == nil {
|
||||
nc.Publish("res", errResBytes)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -70,7 +79,26 @@ func NewStore(m *nats.Msg) {
|
|||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
errRes := Response {
|
||||
Code: 500,
|
||||
Message: http.StatusText(http.StatusInternalServerError),
|
||||
Client: storeRequest.Bite.Client,
|
||||
}
|
||||
errResBytes, errResErr := proto.Marshal(&errRes)
|
||||
if errResErr == nil {
|
||||
nc.Publish("res", errResBytes)
|
||||
}
|
||||
return
|
||||
} else {
|
||||
res := Response {
|
||||
Code: 200,
|
||||
Message: []byte(key),
|
||||
Client: storeRequest.Bite.Client,
|
||||
}
|
||||
resBytes, resErr := proto.Marshal(&res)
|
||||
if resErr == nil {
|
||||
nc.Publish("res", resBytes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue