go-chatgpt-api / middleware /check_header.go
dvc890's picture
Upload 25 files
36a4021
raw
history blame
507 Bytes
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()
}
}