mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: use any rather than interface{} (#74066)
This commit is contained in:
@@ -98,7 +98,7 @@ func (r *NormalResponse) WriteTo(ctx *contextmodel.ReqContext) {
|
||||
}
|
||||
|
||||
func (r *NormalResponse) writeLogLine(c *contextmodel.ReqContext) {
|
||||
v := map[string]interface{}{}
|
||||
v := map[string]any{}
|
||||
traceID := tracing.TraceIDFromContext(c.Req.Context(), false)
|
||||
if err := json.Unmarshal(r.body.Bytes(), &v); err == nil {
|
||||
v["traceID"] = traceID
|
||||
@@ -122,7 +122,7 @@ func (r *NormalResponse) SetHeader(key, value string) *NormalResponse {
|
||||
|
||||
// StreamingResponse is a response that streams itself back to the client.
|
||||
type StreamingResponse struct {
|
||||
body interface{}
|
||||
body any
|
||||
status int
|
||||
header http.Header
|
||||
}
|
||||
@@ -181,13 +181,13 @@ func (r *RedirectResponse) Body() []byte {
|
||||
}
|
||||
|
||||
// JSON creates a JSON response.
|
||||
func JSON(status int, body interface{}) *NormalResponse {
|
||||
func JSON(status int, body any) *NormalResponse {
|
||||
return Respond(status, body).
|
||||
SetHeader("Content-Type", "application/json")
|
||||
}
|
||||
|
||||
// JSONStreaming creates a streaming JSON response.
|
||||
func JSONStreaming(status int, body interface{}) StreamingResponse {
|
||||
func JSONStreaming(status int, body any) StreamingResponse {
|
||||
header := make(http.Header)
|
||||
header.Set("Content-Type", "application/json")
|
||||
return StreamingResponse{
|
||||
@@ -198,13 +198,13 @@ func JSONStreaming(status int, body interface{}) StreamingResponse {
|
||||
}
|
||||
|
||||
// JSONDownload creates a JSON response indicating that it should be downloaded.
|
||||
func JSONDownload(status int, body interface{}, filename string) *NormalResponse {
|
||||
func JSONDownload(status int, body any, filename string) *NormalResponse {
|
||||
return JSON(status, body).
|
||||
SetHeader("Content-Disposition", fmt.Sprintf(`attachment;filename="%s"`, filename))
|
||||
}
|
||||
|
||||
// YAML creates a YAML response.
|
||||
func YAML(status int, body interface{}) *NormalResponse {
|
||||
func YAML(status int, body any) *NormalResponse {
|
||||
b, err := yaml.Marshal(body)
|
||||
if err != nil {
|
||||
return Error(http.StatusInternalServerError, "body yaml marshal", err)
|
||||
@@ -215,7 +215,7 @@ func YAML(status int, body interface{}) *NormalResponse {
|
||||
}
|
||||
|
||||
// YAMLDownload creates a YAML response indicating that it should be downloaded.
|
||||
func YAMLDownload(status int, body interface{}, filename string) *NormalResponse {
|
||||
func YAMLDownload(status int, body any, filename string) *NormalResponse {
|
||||
return YAML(status, body).
|
||||
SetHeader("Content-Type", "application/yaml").
|
||||
SetHeader("Content-Disposition", fmt.Sprintf(`attachment;filename="%s"`, filename))
|
||||
@@ -223,14 +223,14 @@ func YAMLDownload(status int, body interface{}, filename string) *NormalResponse
|
||||
|
||||
// Success create a successful response
|
||||
func Success(message string) *NormalResponse {
|
||||
resp := make(map[string]interface{})
|
||||
resp := make(map[string]any)
|
||||
resp["message"] = message
|
||||
return JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// Error creates an error response.
|
||||
func Error(status int, message string, err error) *NormalResponse {
|
||||
data := make(map[string]interface{})
|
||||
data := make(map[string]any)
|
||||
|
||||
switch status {
|
||||
case 404:
|
||||
@@ -295,7 +295,7 @@ func Empty(status int) *NormalResponse {
|
||||
}
|
||||
|
||||
// Respond creates a response.
|
||||
func Respond(status int, body interface{}) *NormalResponse {
|
||||
func Respond(status int, body any) *NormalResponse {
|
||||
var b []byte
|
||||
switch t := body.(type) {
|
||||
case []byte:
|
||||
|
||||
Reference in New Issue
Block a user