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" ) type Promotion struct{} func GetPromotion() Promotion { return Promotion{} } func (s Promotion) GenerateVoucherPromotion(p model.GenerateVoucherPromotionRequest) (*model.ResponseGenerateVoucherPromotion, error) { msg, err := natsio.GetServer().Request(subject.Promotion.GenerateVoucherPromotion, toBytes(p)) if err != nil { return nil, err } var r struct { Data *model.ResponseGenerateVoucherPromotion `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 }