package middleware

import (
	"gadmin/internal/admin/consts"
	"gadmin/utility/serializer"
	"github.com/gin-gonic/gin"
	"os"
)

func ApiToken() gin.HandlerFunc {
	return func(c *gin.Context) {
		if os.Getenv("RELEASE_GM_API_TOKEN") != c.GetHeader("token") {
			c.JSON(200, serializer.Response{
				Code: consts.CodeCheckLogin,
				Msg:  "token认证失败！",
			})
			c.Abort()
			return
		}
		c.Next()
		return
	}
}
