natsio/client/bank.go

40 lines
706 B
Go
Raw Permalink Normal View History

2022-09-14 07:09:48 +00:00
package client
import (
"encoding/json"
"errors"
"github.com/Selly-Modules/natsio"
"github.com/Selly-Modules/natsio/model"
"github.com/Selly-Modules/natsio/subject"
)
// Bank ...
type Bank struct{}
// GetBank ...
func GetBank() Bank {
return Bank{}
}
2022-09-14 10:23:01 +00:00
func (s Bank) GetBankById(bankID string) (*model.BankBrief, error) {
2022-09-14 07:09:48 +00:00
msg, err := natsio.GetServer().Request(subject.Bank.GetBankById, toBytes(bankID))
if err != nil {
return nil, err
}
var r struct {
Data *model.BankBrief `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
}