Merge pull request #4 from Selly-Modules/v1

[Update] Add sync data with jetstream
This commit is contained in:
Nam Huynh 2022-03-18 13:23:08 +07:00 committed by GitHub
commit 9f52d2bab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions

View File

@ -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
}