hi-server/internal/middleware/apiVersionSwitchHandler.go
shanshanzhong 149dfe1ac3
Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 7m57s
fix gitea workflow path and runner label
2026-03-04 07:02:51 -08:00

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)
}
}