-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (33 loc) · 828 Bytes
/
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
39
40
package main
import (
"context"
"github.com/gin-gonic/gin"
"google.golang.org/grpc"
basketballPlayer "basic-gRPC-proto"
"log"
)
func main() {
router := gin.Default()
rg := router.Group("api/v1/basketballPlayer")
{
rg.GET("/:id", fetchBasketballPlayer)
// Add more routes here later
}
router.Run()
}
func fetchBasketballPlayer(c *gin.Context) {
sAddress := "<yourServerIP>:50051"
conn, e := grpc.Dial(sAddress, grpc.WithInsecure())
if e != nil {
log.Fatalf("Failed to connect to server %v", e)
}
defer conn.Close()
client := basketballPlayer.NewPlayerServiceClient(conn)
player, e := client.GetBasketballPlayer(context.Background(), &basketballPlayer.PlayerRequest{
Id: c.Param("id"),
})
if e != nil {
log.Fatalf("Failed to get player data: %v", e)
}
c.JSON(200, &player)
}