Skip to content

Commit

Permalink
Remove generation of deprecated middlwares (#3441)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael authored Jan 8, 2024
1 parent f2a086b commit 1152f7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 57 deletions.
13 changes: 1 addition & 12 deletions http/codegen/example_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func exampleServer(genpkg string, root *expr.RootExpr, svr *expr.ServerExpr) *co
},
FuncMap: map[string]any{"needStream": needStream, "hasWebSocket": hasWebSocket},
},
{Name: "server-http-middleware", Source: httpSvrMiddlewareT},
{
Name: "server-http-end",
Source: httpSvrEndT,
Expand Down Expand Up @@ -273,21 +272,11 @@ func handleHTTPServer(ctx context.Context, u *url.URL{{ range $.Services }}{{ if
{{- end }}
`

httpSvrMiddlewareT = `
// Wrap the multiplexer with additional middlewares. Middlewares mounted
// here apply to all the service endpoints.
var handler http.Handler = mux
{
handler = httpmdlwr.Log(adapter)(handler)
handler = httpmdlwr.RequestID()(handler)
}
`

// input: map[string]any{"Services":[]*ServiceData}
httpSvrEndT = `
// Start HTTP server using default configuration, change the code to
// configure the server as required by your service.
srv := &http.Server{Addr: u.Host, Handler: handler, ReadHeaderTimeout: time.Second * 60}
srv := &http.Server{Addr: u.Host, Handler: mux, ReadHeaderTimeout: time.Second * 60}
{{- range .Services }}
for _, m := range {{ .Service.VarName }}Server.Mounts {
Expand Down
50 changes: 5 additions & 45 deletions http/codegen/testdata/example_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,9 @@ func handleHTTPServer(ctx context.Context, u *url.URL, serviceEndpoints *service
// Configure the mux.
servicesvr.Mount(mux, serviceServer)
// Wrap the multiplexer with additional middlewares. Middlewares mounted
// here apply to all the service endpoints.
var handler http.Handler = mux
{
handler = httpmdlwr.Log(adapter)(handler)
handler = httpmdlwr.RequestID()(handler)
}
// Start HTTP server using default configuration, change the code to
// configure the server as required by your service.
srv := &http.Server{Addr: u.Host, Handler: handler, ReadHeaderTimeout: time.Second * 60}
srv := &http.Server{Addr: u.Host, Handler: mux, ReadHeaderTimeout: time.Second * 60}
for _, m := range serviceServer.Mounts {
logger.Printf("HTTP %q mounted on %s %s", m.Method, m.Verb, m.Pattern)
}
Expand Down Expand Up @@ -148,17 +140,9 @@ func handleHTTPServer(ctx context.Context, u *url.URL, wg *sync.WaitGroup, errc
// Configure the mux.
servicesvr.Mount(mux, serviceServer)
// Wrap the multiplexer with additional middlewares. Middlewares mounted
// here apply to all the service endpoints.
var handler http.Handler = mux
{
handler = httpmdlwr.Log(adapter)(handler)
handler = httpmdlwr.RequestID()(handler)
}
// Start HTTP server using default configuration, change the code to
// configure the server as required by your service.
srv := &http.Server{Addr: u.Host, Handler: handler, ReadHeaderTimeout: time.Second * 60}
srv := &http.Server{Addr: u.Host, Handler: mux, ReadHeaderTimeout: time.Second * 60}
for _, m := range serviceServer.Mounts {
logger.Printf("HTTP %q mounted on %s %s", m.Method, m.Verb, m.Pattern)
}
Expand Down Expand Up @@ -247,17 +231,9 @@ func handleHTTPServer(ctx context.Context, u *url.URL, serviceEndpoints *service
// Configure the mux.
servicesvr.Mount(mux, serviceServer)
// Wrap the multiplexer with additional middlewares. Middlewares mounted
// here apply to all the service endpoints.
var handler http.Handler = mux
{
handler = httpmdlwr.Log(adapter)(handler)
handler = httpmdlwr.RequestID()(handler)
}
// Start HTTP server using default configuration, change the code to
// configure the server as required by your service.
srv := &http.Server{Addr: u.Host, Handler: handler, ReadHeaderTimeout: time.Second * 60}
srv := &http.Server{Addr: u.Host, Handler: mux, ReadHeaderTimeout: time.Second * 60}
for _, m := range serviceServer.Mounts {
logger.Printf("HTTP %q mounted on %s %s", m.Method, m.Verb, m.Pattern)
}
Expand Down Expand Up @@ -350,17 +326,9 @@ func handleHTTPServer(ctx context.Context, u *url.URL, serviceEndpoints *service
servicesvr.Mount(mux, serviceServer)
anotherservicesvr.Mount(mux, anotherServiceServer)
// Wrap the multiplexer with additional middlewares. Middlewares mounted
// here apply to all the service endpoints.
var handler http.Handler = mux
{
handler = httpmdlwr.Log(adapter)(handler)
handler = httpmdlwr.RequestID()(handler)
}
// Start HTTP server using default configuration, change the code to
// configure the server as required by your service.
srv := &http.Server{Addr: u.Host, Handler: handler, ReadHeaderTimeout: time.Second * 60}
srv := &http.Server{Addr: u.Host, Handler: mux, ReadHeaderTimeout: time.Second * 60}
for _, m := range serviceServer.Mounts {
logger.Printf("HTTP %q mounted on %s %s", m.Method, m.Verb, m.Pattern)
}
Expand Down Expand Up @@ -457,17 +425,9 @@ func handleHTTPServer(ctx context.Context, u *url.URL, streamingServiceAEndpoint
streamingserviceasvr.Mount(mux, streamingServiceAServer)
streamingservicebsvr.Mount(mux, streamingServiceBServer)
// Wrap the multiplexer with additional middlewares. Middlewares mounted
// here apply to all the service endpoints.
var handler http.Handler = mux
{
handler = httpmdlwr.Log(adapter)(handler)
handler = httpmdlwr.RequestID()(handler)
}
// Start HTTP server using default configuration, change the code to
// configure the server as required by your service.
srv := &http.Server{Addr: u.Host, Handler: handler, ReadHeaderTimeout: time.Second * 60}
srv := &http.Server{Addr: u.Host, Handler: mux, ReadHeaderTimeout: time.Second * 60}
for _, m := range streamingServiceAServer.Mounts {
logger.Printf("HTTP %q mounted on %s %s", m.Method, m.Verb, m.Pattern)
}
Expand Down

0 comments on commit 1152f7d

Please sign in to comment.