Spaces:
Runtime error
Runtime error
File size: 507 Bytes
36a4021 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
package middleware
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/linweiyuan/go-chatgpt-api/api"
)
func CheckHeaderMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
if c.GetHeader(api.AuthorizationHeader) == "" &&
c.Request.URL.Path != "/chatgpt/login" &&
c.Request.URL.Path != "/platform/login" {
c.AbortWithStatusJSON(http.StatusUnauthorized, api.ReturnMessage("Missing accessToken."))
return
}
c.Header("Content-Type", "application/json")
c.Next()
}
}
|