mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 18:35:51 +02:00
27 lines
713 B
Go
27 lines
713 B
Go
package api
|
|
|
|
import (
|
|
"github.com/0xJacky/Nginx-UI/model"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/uozi-tech/cosy/logger"
|
|
"net/http"
|
|
)
|
|
|
|
func CurrentUser(c *gin.Context) *model.User {
|
|
return c.MustGet("user").(*model.User)
|
|
}
|
|
|
|
func ErrHandler(c *gin.Context, err error) {
|
|
logger.GetLogger().Errorln(err)
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
"message": err.Error(),
|
|
})
|
|
}
|
|
|
|
func SetSSEHeaders(c *gin.Context) {
|
|
c.Header("Content-Type", "text/event-stream")
|
|
c.Header("Cache-Control", "no-cache")
|
|
c.Header("Connection", "keep-alive")
|
|
// https://stackoverflow.com/questions/27898622/server-sent-events-stopped-work-after-enabling-ssl-on-proxy/27960243#27960243
|
|
c.Header("X-Accel-Buffering", "no")
|
|
}
|