-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NATS integration and order placement refinements
Introduced a new NATS package for message publishing and subscribing. Modified the order placement function to include user ID and ensure cart items are removed post-order placement. Updated dependencies to include NATS-related packages.
- Loading branch information
1 parent
c90c3c8
commit fcf11fa
Showing
6 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package nats | ||
|
||
import ( | ||
"github.com/nats-io/nats.go" | ||
"log" | ||
) | ||
|
||
type NATS struct { | ||
conn *nats.Conn | ||
} | ||
|
||
func NewNATS() (*NATS, error) { | ||
nc, err := nats.Connect(nats.DefaultURL, nats.Name("food-delivery-nats")) | ||
if err != nil { | ||
log.Fatalf("Error: %s", err) | ||
} | ||
return &NATS{conn: nc}, err | ||
} | ||
|
||
func (n *NATS) Publish(channel string, message []byte) error { | ||
err := n.conn.Publish(channel, message) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (n *NATS) Subscribe(channel string) error { | ||
_, err := n.conn.Subscribe(channel, func(msg *nats.Msg) { | ||
log.Printf("Received a message: %s", string(msg.Data)) | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters