Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 7m57s
24 lines
531 B
Go
24 lines
531 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/perfect-panel/server/pkg/constant"
|
|
)
|
|
|
|
func ApiVersionSwitchHandler(legacyHandler gin.HandlerFunc, latestHandler gin.HandlerFunc) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
useLatest, _ := c.Request.Context().Value(constant.CtxKeyAPIVersionUseLatest).(bool)
|
|
if useLatest && latestHandler != nil {
|
|
latestHandler(c)
|
|
return
|
|
}
|
|
if legacyHandler != nil {
|
|
legacyHandler(c)
|
|
return
|
|
}
|
|
c.AbortWithStatus(http.StatusNotFound)
|
|
}
|
|
}
|