Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func routeOrQuery(c *gin.Context, routeName, queryName string) string {
|
||||
if c == nil {
|
||||
return ""
|
||||
}
|
||||
if value := strings.TrimSpace(c.Param(routeName)); value != "" {
|
||||
return value
|
||||
}
|
||||
return strings.TrimSpace(c.Query(queryName))
|
||||
}
|
||||
|
||||
func hasQuery(c *gin.Context, names ...string) bool {
|
||||
if c == nil || c.Request == nil || c.Request.URL == nil {
|
||||
return false
|
||||
}
|
||||
values := c.Request.URL.Query()
|
||||
for _, name := range names {
|
||||
if _, ok := values[name]; ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func redirectCanonical(c *gin.Context, target string) bool {
|
||||
target = strings.TrimSpace(target)
|
||||
if c == nil || target == "" || c.Request == nil || c.Request.URL == nil {
|
||||
return false
|
||||
}
|
||||
if c.Request.URL.RequestURI() == target {
|
||||
return false
|
||||
}
|
||||
c.Redirect(http.StatusMovedPermanently, target)
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user