Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
baytan0720 committed Oct 3, 2023
1 parent d50d3b0 commit 83f686a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,34 @@ func main() {
e := gin.Default(&Server{})
proto.RegisterHelloServer(e, e.Srv.(*Server))

e.Use(gin.StoreRequestIntoKeys())

e.Handle("Ping", func(c *gin.Context) {
var req *proto.PingReq
c.BindRequest(&req)
fmt.Printf("ID: %s\n", req.Id)
fmt.Printf("ID: %s\n", c.GetString("Id"))
fmt.Printf("ID: %s\n", c.Req.GetField("Id"))
c.Response(&proto.PongRes{
Status: 1,
})

// another way to response:
//
//c.ResponseField("Status", int32(1))
//
//c.ResponseFields(gin.H{
// "Status": int32(1),
//})
})

panic(e.Run()) // listen and serve on 0.0.0.0:8080
e.Run() // listen and serve on 8080
}

func (s *Server) Ping(ctx context.Context, req *proto.PingReq) (*proto.PongRes, error) {
return &proto.PongRes{}, nil
}

```

You just need to define a struct and implement the interface `proto.HelloServer` without any logic.
Expand Down
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func main() {
//})
})

panic(e.Run()) // listen and serve on 8080
e.Run() // listen and serve on 8080
}

func (s *Server) Ping(ctx context.Context, req *proto.PingReq) (*proto.PongRes, error) {
Expand Down

0 comments on commit 83f686a

Please # to comment.