mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00

The new golangci-lint version 1.60.1 has problems with typecheck when linting remote files. We have certain pakcages that should never be inlcuded in remote but the typecheck tries to compile all of them but this never works and it seems to ignore the exclude files we gave it. To fix this the proper way is to mark all packages we only use locally with !remote tags. This is a bit ugly but more correct. I also moved the DecodeChanges() code around as it is called from the client so the handles package which should only be remote doesn't really fit anyway. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
35 lines
946 B
Go
35 lines
946 B
Go
//go:build !remote
|
|
|
|
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"runtime"
|
|
|
|
"github.com/containers/podman/v5/pkg/api/handlers/utils"
|
|
"github.com/gorilla/mux"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// panicHandler captures panics from endpoint handlers and logs stack trace
|
|
func panicHandler() mux.MiddlewareFunc {
|
|
return func(h http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// http.Server hides panics from handlers, we want to record them and fix the cause
|
|
defer func() {
|
|
err := recover()
|
|
if err != nil {
|
|
buf := make([]byte, 1<<20)
|
|
n := runtime.Stack(buf, true)
|
|
logrus.Warnf("Recovering from API service endpoint handler panic: %v, %s", err, buf[:n])
|
|
// Try to inform client things went south... won't work if handler already started writing response body
|
|
utils.InternalServerError(w, fmt.Errorf("%v", err))
|
|
}
|
|
}()
|
|
|
|
h.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
}
|