define order client
This commit is contained in:
		
							parent
							
								
									0eb670a0c5
								
							
						
					
					
						commit
						56e810378e
					
				| 
						 | 
					@ -0,0 +1,36 @@
 | 
				
			||||||
 | 
					package client
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio"
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio/model"
 | 
				
			||||||
 | 
						"github.com/Selly-Modules/natsio/subject"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Order ...
 | 
				
			||||||
 | 
					type Order struct{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetOrder ...
 | 
				
			||||||
 | 
					func GetOrder() Order {
 | 
				
			||||||
 | 
						return Order{}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// UpdateORStatus ...
 | 
				
			||||||
 | 
					func (w Order) UpdateORStatus(p model.OrderUpdateORStatus) error {
 | 
				
			||||||
 | 
						msg, err := natsio.GetServer().Request(subject.OrderUpdateORStatus, 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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -16,6 +16,8 @@ func (e JSONEncoder) Subscribe(subject string, cb nats.Handler) (*nats.Subscript
 | 
				
			||||||
	sub, err := e.encConn.Subscribe(subject, cb)
 | 
						sub, err := e.encConn.Subscribe(subject, cb)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Printf("natsio.JSONEncoder.Subscribe err: %v\n", err)
 | 
							log.Printf("natsio.JSONEncoder.Subscribe err: %v\n", err)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							log.Printf("natsio.JSONEncoder - subscribed to subject %s successfully\n", subject)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return sub, err
 | 
						return sub, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,9 @@
 | 
				
			||||||
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// OrderUpdateORStatus ...
 | 
				
			||||||
 | 
					type OrderUpdateORStatus struct {
 | 
				
			||||||
 | 
						OrderCode string `json:"orderCode"`
 | 
				
			||||||
 | 
						ORCode    string `json:"orCode"`
 | 
				
			||||||
 | 
						Status    string `json:"status"`
 | 
				
			||||||
 | 
						Reason    string `json:"reason"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,7 @@
 | 
				
			||||||
 | 
					package subject
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const orderPrefix = "order_"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						OrderUpdateORStatus = orderPrefix + "update_outbound_request_status"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
		Loading…
	
		Reference in New Issue