Skip to content

Commit

Permalink
Create api_gateway.go
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 7, 2024
1 parent 77af82e commit e206f84
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions sdk/api/api_gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package api

import (
"context"
"fmt"
"log"
"net/http"

"github.com/KOSASIH/pi-nexus-autonomous-banking-network/sdk/api/pb"
"google.golang.org/grpc"
)

type APIGateway struct {
pb.UnimplementedAPIGatewayServer
}

func (g *APIGateway) HandleRequest(ctx context.Context, req *pb.Request) (*pb.Response, error) {
// TO DO: implement API request handling logic
log.Printf("Received API request from %s", req.ClientID)
return &pb.Response{Result: "success"}, nil
}

func main() {
lis, err := net.Listen("tcp", ":50054")
if err != nil {
log.Fatalf("failed to listen: %v", err)
}

srv := grpc.NewServer()
pb.RegisterAPIGatewayServer(srv, &APIGateway{})

log.Println("API gateway listening on port 50054")
srv.Serve(lis)

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "PiNexus SDK API Gateway")
})

log.Println("HTTP server listening on port 8080")
http.ListenAndServe(":8080", nil)
}

0 comments on commit e206f84

Please sign in to comment.