define nats product
This commit is contained in:
		
							parent
							
								
									46539db236
								
							
						
					
					
						commit
						b19fea04c8
					
				| 
						 | 
				
			
			@ -0,0 +1,35 @@
 | 
			
		|||
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"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Product ...
 | 
			
		||||
type Product struct{}
 | 
			
		||||
 | 
			
		||||
// GetProduct ...
 | 
			
		||||
func GetProduct() Product {
 | 
			
		||||
	return Product{}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c Product) ApplyRequest(p model.ProductApplyRequestPayload) error {
 | 
			
		||||
	msg, err := natsio.GetServer().Request(subject.Product.ApplyRequest, toBytes(p))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	var r struct {
 | 
			
		||||
		Error string `json:"error"`
 | 
			
		||||
	}
 | 
			
		||||
	if err = json.Unmarshal(msg.Data, &r); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	if r.Error != "" {
 | 
			
		||||
		return errors.New(r.Error)
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
package model
 | 
			
		||||
 | 
			
		||||
type ProductApplyRequestPayload struct {
 | 
			
		||||
	RequestID string `json:"requestId"`
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -14,6 +14,7 @@ var prefixes = struct {
 | 
			
		|||
	SocialPost    string
 | 
			
		||||
	Staff         string
 | 
			
		||||
	Segment       string
 | 
			
		||||
	Product       string
 | 
			
		||||
	Campaign      string
 | 
			
		||||
	Affiliate     string
 | 
			
		||||
}{
 | 
			
		||||
| 
						 | 
				
			
			@ -30,6 +31,7 @@ var prefixes = struct {
 | 
			
		|||
	SocialPost:    "social_post",
 | 
			
		||||
	Staff:         "staff",
 | 
			
		||||
	Segment:       "segment",
 | 
			
		||||
	Product:       "product",
 | 
			
		||||
	Campaign:      "campaign",
 | 
			
		||||
	Affiliate:     "affiliate",
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,14 @@
 | 
			
		|||
package subject
 | 
			
		||||
 | 
			
		||||
import "fmt"
 | 
			
		||||
 | 
			
		||||
// getSegmentValue ...
 | 
			
		||||
func getProductValue(val string) string {
 | 
			
		||||
	return fmt.Sprintf("%s.%s", prefixes.Product, val)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var Product = struct {
 | 
			
		||||
	ApplyRequest string
 | 
			
		||||
}{
 | 
			
		||||
	ApplyRequest: getProductValue("apply_request"),
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue