@@ -84,27 +84,27 @@ func main() {
84
84
if err != nil {
85
85
log .WithError (err ).Fatal ("failed to listen" )
86
86
}
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 ())
90
90
91
91
// 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 ) {
95
95
_ , _ = w .Write ([]byte ("Hello, world!" ))
96
96
})
97
97
98
- mux .HandleFunc ("/health" , func (w http.ResponseWriter , r * http.Request ) {
98
+ httpMux .HandleFunc ("/health" , func (w http.ResponseWriter , r * http.Request ) {
99
99
_ , _ = w .Write ([]byte ("healthy" ))
100
100
})
101
101
102
102
static , _ := fs .Sub (swagfs , "swagger" )
103
- mux .Handle ("/" , http .FileServer (http .FS (static )))
103
+ httpMux .Handle ("/" , http .FileServer (http .FS (static )))
104
104
105
105
// Main GRPC Server
106
- grpcS := grpc .NewServer ()
107
- pb .RegisterCampusServer (grpcS , campusService )
106
+ grpcServer := grpc .NewServer ()
107
+ pb .RegisterCampusServer (grpcServer , campusService )
108
108
109
109
// GRPC Gateway for HTTP REST -> GRPC
110
110
grpcGatewayMux := runtime .NewServeMux (runtime .WithIncomingHeaderMatcher (
@@ -118,23 +118,21 @@ func main() {
118
118
}),
119
119
runtime .WithErrorHandler (errorHandler ),
120
120
)
121
- ctx := context .Background ()
122
121
opts := []grpc.DialOption {
123
122
grpc .WithTransportCredentials (insecure .NewCredentials ()),
124
123
grpc .WithUserAgent ("internal" ),
125
124
grpc .WithUnaryInterceptor (addMethodNameInterceptor ),
126
125
}
127
- if err := pb .RegisterCampusHandlerFromEndpoint (ctx , grpcGatewayMux , httpPort , opts ); err != nil {
126
+ if err := pb .RegisterCampusHandlerFromEndpoint (context . Background () , grpcGatewayMux , httpPort , opts ); err != nil {
128
127
log .WithError (err ).Panic ("could not RegisterCampusHandlerFromEndpoint" )
129
128
}
130
- restPrefix := "/v1"
131
- mux .Handle ("/v1/" , http .StripPrefix (restPrefix , grpcGatewayMux ))
129
+ httpMux .Handle ("/v1/" , http .StripPrefix ("/v1" , grpcGatewayMux ))
132
130
133
131
// Start each server in its own go routine and logs any errors
134
132
g := errgroup.Group {}
135
- g .Go (func () error { return grpcS .Serve (grpcListener ) })
133
+ g .Go (func () error { return grpcServer .Serve (grpcListener ) })
136
134
g .Go (func () error { return httpServer .Serve (httpListener ) })
137
- g .Go (func () error { return m .Serve () })
135
+ g .Go (func () error { return mux .Serve () })
138
136
g .Go (func () error { return cronService .Run () }) // Setup cron jobs
139
137
g .Go (func () error { return campusService .RunDeviceFlusher () }) // Setup campus service
140
138
0 commit comments