mirror of
https://github.com/pushbits/server.git
synced 2025-04-30 18:57:17 +02:00
22 lines
430 B
Go
22 lines
430 B
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type idInURI struct {
|
|
ID uint `uri:"id" binding:"required"`
|
|
}
|
|
|
|
// RequireIDInURI returns a Gin middleware which requires an ID to be supplied in the URI of the request.
|
|
func RequireIDInURI() gin.HandlerFunc {
|
|
return func(ctx *gin.Context) {
|
|
var requestModel idInURI
|
|
|
|
if err := ctx.BindUri(&requestModel); err != nil {
|
|
return
|
|
}
|
|
|
|
ctx.Set("id", requestModel.ID)
|
|
}
|
|
}
|