-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (34 loc) · 1.1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"context"
"fmt"
"github.com/Njunwa1/fupi.tz-proto/golang/url"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"log"
"net/http"
)
var shortenerServiceAddr string
func main() {
// Set up a connection to the shortener server.
serverAddr := "localhost:50051"
log.Print(shortenerServiceAddr)
conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("could not connect to shortener service: %v", err)
}
defer conn.Close()
// Register gRPC server endpoint
// Note: Make sure the gRPC server is running properly and accessible
mux := runtime.NewServeMux()
if err = url.RegisterUrlHandler(context.Background(), mux, conn); err != nil {
log.Fatalf("failed to register the order server: %v", err)
}
// start listening to requests from the gateway server
addr := "0.0.0.0:8080"
fmt.Println("API gateway server is running on " + addr)
if err = http.ListenAndServe(addr, mux); err != nil {
log.Fatal("gateway server closed abruptly: ", err)
}
}