mirror of
https://github.com/komari-monitor/komari.git
synced 2026-11-21 07:10:47 +00:00
Add settings for allowed CORS origins and WebSocket origin validation so deployments can restrict cross-origin access instead of using a global wildcard policy. Move CORS handling into the security middleware and update report cache usage to use the dedicated report package.
34 lines
974 B
Go
34 lines
974 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Response struct {
|
|
Status string `json:"status"`
|
|
Message string `json:"message"`
|
|
Data interface{} `json:"data,omitempty"`
|
|
}
|
|
|
|
// Respond sends a standardized JSON response.
|
|
func Respond(c *gin.Context, httpStatus int, status string, message string, data interface{}) {
|
|
c.JSON(httpStatus, Response{Status: status, Message: message, Data: data})
|
|
}
|
|
|
|
// RespondSuccess sends a success response with data.
|
|
func RespondSuccess(c *gin.Context, data interface{}) {
|
|
Respond(c, http.StatusOK, "success", "", data)
|
|
}
|
|
|
|
// RespondSuccessMessage sends a success response with message and data.
|
|
func RespondSuccessMessage(c *gin.Context, message string, data interface{}) {
|
|
Respond(c, http.StatusOK, "success", message, data)
|
|
}
|
|
|
|
// RespondError sends an error response with message.
|
|
func RespondError(c *gin.Context, httpStatus int, message string) {
|
|
Respond(c, httpStatus, "error", message, nil)
|
|
}
|