Merge pull request #4 from Selly-Modules/v1
[Update] Add sync data with jetstream
This commit is contained in:
commit
9f52d2bab4
|
@ -40,6 +40,29 @@ func NewClient(config Config) (*Client, error) {
|
|||
// SyncData
|
||||
// Sync data to services ES
|
||||
func (c *Client) SyncData(data SyncData) (bool, error) {
|
||||
var (
|
||||
req = RequestBody{
|
||||
ApiKey: c.Config.ApiKey,
|
||||
Body: toBytes(data),
|
||||
}
|
||||
res *Response
|
||||
)
|
||||
msg, err := c.natsServer.Request(SubjectSyncData, toBytes(req))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if err = json.Unmarshal(msg.Data, &res); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if res.Message != "" {
|
||||
return false, errors.New(res.Message)
|
||||
}
|
||||
return res.Success, nil
|
||||
}
|
||||
|
||||
// SyncDataWithJetStream
|
||||
// Sync data to services ES with JetStream
|
||||
func (c *Client) SyncDataWithJetStream(data SyncData) (bool, error) {
|
||||
var (
|
||||
req = RequestBody{
|
||||
ApiKey: c.Config.ApiKey,
|
||||
|
@ -50,6 +73,7 @@ func (c *Client) SyncData(data SyncData) (bool, error) {
|
|||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue