Skip to content

Commit cdc891b

Browse files
renamed a few things to be closer to what they actually are
1 parent 4ec69b6 commit cdc891b

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

server/main.go

+14-16
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,27 @@ func main() {
8484
if err != nil {
8585
log.WithError(err).Fatal("failed to listen")
8686
}
87-
m := cmux.New(listener)
88-
grpcListener := m.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"))
89-
httpListener := m.Match(cmux.HTTP1Fast())
87+
mux := cmux.New(listener)
88+
grpcListener := mux.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"))
89+
httpListener := mux.Match(cmux.HTTP1Fast())
9090

9191
// HTTP Stuff
92-
mux := http.NewServeMux()
93-
httpServer := &http.Server{Handler: mux}
94-
mux.HandleFunc("/imprint", func(w http.ResponseWriter, r *http.Request) {
92+
httpMux := http.NewServeMux()
93+
httpServer := &http.Server{Handler: httpMux}
94+
httpMux.HandleFunc("/imprint", func(w http.ResponseWriter, r *http.Request) {
9595
_, _ = w.Write([]byte("Hello, world!"))
9696
})
9797

98-
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
98+
httpMux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
9999
_, _ = w.Write([]byte("healthy"))
100100
})
101101

102102
static, _ := fs.Sub(swagfs, "swagger")
103-
mux.Handle("/", http.FileServer(http.FS(static)))
103+
httpMux.Handle("/", http.FileServer(http.FS(static)))
104104

105105
// Main GRPC Server
106-
grpcS := grpc.NewServer()
107-
pb.RegisterCampusServer(grpcS, campusService)
106+
grpcServer := grpc.NewServer()
107+
pb.RegisterCampusServer(grpcServer, campusService)
108108

109109
// GRPC Gateway for HTTP REST -> GRPC
110110
grpcGatewayMux := runtime.NewServeMux(runtime.WithIncomingHeaderMatcher(
@@ -118,23 +118,21 @@ func main() {
118118
}),
119119
runtime.WithErrorHandler(errorHandler),
120120
)
121-
ctx := context.Background()
122121
opts := []grpc.DialOption{
123122
grpc.WithTransportCredentials(insecure.NewCredentials()),
124123
grpc.WithUserAgent("internal"),
125124
grpc.WithUnaryInterceptor(addMethodNameInterceptor),
126125
}
127-
if err := pb.RegisterCampusHandlerFromEndpoint(ctx, grpcGatewayMux, httpPort, opts); err != nil {
126+
if err := pb.RegisterCampusHandlerFromEndpoint(context.Background(), grpcGatewayMux, httpPort, opts); err != nil {
128127
log.WithError(err).Panic("could not RegisterCampusHandlerFromEndpoint")
129128
}
130-
restPrefix := "/v1"
131-
mux.Handle("/v1/", http.StripPrefix(restPrefix, grpcGatewayMux))
129+
httpMux.Handle("/v1/", http.StripPrefix("/v1", grpcGatewayMux))
132130

133131
// Start each server in its own go routine and logs any errors
134132
g := errgroup.Group{}
135-
g.Go(func() error { return grpcS.Serve(grpcListener) })
133+
g.Go(func() error { return grpcServer.Serve(grpcListener) })
136134
g.Go(func() error { return httpServer.Serve(httpListener) })
137-
g.Go(func() error { return m.Serve() })
135+
g.Go(func() error { return mux.Serve() })
138136
g.Go(func() error { return cronService.Run() }) // Setup cron jobs
139137
g.Go(func() error { return campusService.RunDeviceFlusher() }) // Setup campus service
140138

0 commit comments

Comments
 (0)