github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/server/httputils/iface.go (about) 1 package httputils 2 3 import ( 4 "net/http" 5 6 "github.com/sirupsen/logrus" 7 ) 8 9 // TODO(petethepig): this interface is pretty large, we can probably simplify it, some methods do pretty similar things 10 type Utils interface { 11 // these methods were originally extracted from api package 12 MustJSON(r *http.Request, w http.ResponseWriter, v interface{}) 13 HandleError(r *http.Request, w http.ResponseWriter, err error) 14 IDFromRequest(r *http.Request) (uint, error) 15 Logger(r *http.Request) logrus.FieldLogger 16 17 // these methods were originally extracted from server package 18 WriteResponseJSON(r *http.Request, w http.ResponseWriter, res interface{}) 19 WriteResponseFile(r *http.Request, w http.ResponseWriter, filename string, content []byte) 20 21 ErrorUtils 22 } 23 24 type ErrorUtils interface { 25 WriteInvalidMethodError(r *http.Request, w http.ResponseWriter) 26 WriteInvalidParameterError(r *http.Request, w http.ResponseWriter, err error) 27 WriteInternalServerError(r *http.Request, w http.ResponseWriter, err error, msg string) 28 WriteJSONEncodeError(r *http.Request, w http.ResponseWriter, err error) 29 WriteError(r *http.Request, w http.ResponseWriter, code int, err error, msg string) 30 }