37 lines
836 B
Go
37 lines
836 B
Go
|
package client
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"errors"
|
||
|
"git.selly.red/Selly-Modules/natsio"
|
||
|
"git.selly.red/Selly-Modules/natsio/model"
|
||
|
"git.selly.red/Selly-Modules/natsio/subject"
|
||
|
)
|
||
|
|
||
|
// Affiliate ...
|
||
|
type Affiliate struct{}
|
||
|
|
||
|
// GetAffiliate ...
|
||
|
func GetAffiliate() Affiliate {
|
||
|
return Affiliate{}
|
||
|
}
|
||
|
|
||
|
// GetTransactions ...
|
||
|
func (w Affiliate) GetTransactions(p model.GetTransactionsRequest) (*model.GetTransactionsResponse, error) {
|
||
|
msg, err := natsio.GetServer().Request(subject.Affiliate.GetTransactions, toBytes(p))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
var r struct {
|
||
|
Data *model.GetTransactionsResponse `json:"data"`
|
||
|
Error string `json:"error"`
|
||
|
}
|
||
|
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if r.Error != "" {
|
||
|
return nil, errors.New(r.Error)
|
||
|
}
|
||
|
return r.Data, nil
|
||
|
}
|