-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (44 loc) · 1.28 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"context"
"flag"
"log"
"net/http"
_ "net/http/pprof"
"connectrpc.com/connect"
"github.com/sudorandom/go-grpc-bench/gen"
"github.com/sudorandom/go-grpc-bench/gen/genconnect"
"go.akshayshah.org/connectproto"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
)
var _ genconnect.FlexServiceHandler = (*server)(nil)
type server struct {
genconnect.UnimplementedFlexServiceHandler
}
// NormalRPC implements genconnect.FlexServiceHandler.
func (s *server) NormalRPC(ctx context.Context, req *connect.Request[gen.FlexRequest]) (*connect.Response[gen.FlexReply], error) {
return connect.NewResponse(&gen.FlexReply{Msg: req.Msg.Msg}), nil
}
func main() {
var withVT bool
flag.BoolVar(&withVT, "withvt", false, "enable vtprotobuf optimizations")
flag.Parse()
log.Printf("Starting connectrpc withVT=%t", withVT)
go func() {
log.Println(http.ListenAndServe("localhost:6669", nil))
}()
mux := http.NewServeMux()
opts := []connect.HandlerOption{}
if withVT {
opts = append(opts, connectproto.WithBinaryVT())
}
mux.Handle(genconnect.NewFlexServiceHandler(&server{}, opts...))
srv := http.Server{
Addr: ":6660",
Handler: h2c.NewHandler(mux, &http2.Server{}),
}
if err := srv.ListenAndServe(); err != nil {
log.Fatalf("listen failed: %s", err)
}
}