@@ -7,11 +7,11 @@ import (
77 "net/http"
88 "time"
99
10- "github.com/aristat/golang-example-app/common"
11- "github.com/nats-io/nats.go"
1210 "github.com/nats-io/stan.go"
1311
12+ "github.com/aristat/golang-example-app/common"
1413 "github.com/go-chi/chi"
14+ "github.com/nats-io/nats.go"
1515
1616 "github.com/aristat/golang-example-app/app/grpc"
1717 "github.com/aristat/golang-example-app/app/logger"
@@ -27,10 +27,11 @@ type Router struct {
2727}
2828
2929func (router * Router ) Run (chiRouter chi.Router ) {
30- chiRouter .Get ("/products" , router .GetProducts )
30+ chiRouter .Get ("/products_grpc" , router .GetProductsGrpc )
31+ chiRouter .Get ("/products_nats" , router .GetProductsNats )
3132}
3233
33- func (service * Router ) GetProducts (w http.ResponseWriter , r * http.Request ) {
34+ func (service * Router ) GetProductsGrpc (w http.ResponseWriter , r * http.Request ) {
3435 conn , d , err := grpc .GetConnGRPC (service .poolManager , common .SrvProducts )
3536 defer d ()
3637 defer r .Body .Close ()
@@ -55,6 +56,10 @@ func (service *Router) GetProducts(w http.ResponseWriter, r *http.Request) {
5556 return
5657 }
5758
59+ e .Encode (productOut )
60+ }
61+ 62+ func (service * Router ) GetProductsNats (w http.ResponseWriter , r * http.Request ) {
5863 // Connect to NATS
5964 nc , err := nats .Connect (service .cfg .NatsURL )
6065 if err != nil {
@@ -73,5 +78,6 @@ func (service *Router) GetProducts(w http.ResponseWriter, r *http.Request) {
7378 // Close connection
7479 sc .Close ()
7580
76- e .Encode (productOut )
81+ e := json .NewEncoder (w )
82+ e .Encode ("" )
7783}
0 commit comments