27 lines
606 B
Go
27 lines
606 B
Go
package middleware
|
|
|
|
import (
|
|
"nixcn-cms/internal/exception"
|
|
"nixcn-cms/utils"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func ApiVersionCheck() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
apiVersion := c.GetHeader("X-Api-Version")
|
|
if apiVersion == "" {
|
|
errorCode := new(exception.Builder).
|
|
SetStatus(exception.StatusServer).
|
|
SetService(exception.MiddlewareServiceApiVersion).
|
|
SetEndpoint(exception.EndpointMiddlewareService).
|
|
SetType(exception.TypeSpecific).
|
|
SetOriginal(exception.ApiVersionNotFound).
|
|
Build(c)
|
|
utils.HttpAbort(c, 400, errorCode)
|
|
return
|
|
}
|
|
c.Next()
|
|
}
|
|
}
|