refactor(api): introduce v1 response contract
This commit is contained in:
18
backend/internal/httpx/params.go
Normal file
18
backend/internal/httpx/params.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package httpx
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// IdentityParam 只接受 UUIDv7 路径参数,避免把内部自增 ID 暴露为外部标识。
|
||||
func IdentityParam(c *gin.Context, name string) (string, bool) {
|
||||
identity, err := uuid.Parse(c.Param(name))
|
||||
if err != nil || identity.Version() != 7 {
|
||||
Error(c, http.StatusBadRequest, "invalid_request", "请求参数无效")
|
||||
return "", false
|
||||
}
|
||||
return identity.String(), true
|
||||
}
|
||||
Reference in New Issue
Block a user