initial commit
This commit is contained in:
commit
d40b69f1f9
58 changed files with 7919 additions and 0 deletions
33
backend/middleware/param.go
Normal file
33
backend/middleware/param.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package middleware
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"git.red-panda.pet/pandaware/house/backend/router"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func ValidateUUIDParam(ctx *router.Context, key string) error {
|
||||
param := ctx.Parameter(key)
|
||||
if err := uuid.Validate(param); err != nil {
|
||||
return ctx.Error(err, 400, "Bad path parameter "+key)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidateIDParam(ctx *router.Context, key string) error {
|
||||
param := ctx.Parameter(key)
|
||||
v, err := strconv.ParseInt(param, 10, 64)
|
||||
if err != nil {
|
||||
return ctx.Error(err, 400, "Bad path parameter "+key)
|
||||
}
|
||||
|
||||
ctx.With(paramsKey, v)
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: expand this kinda api for more than just one param, better validation, etc.
|
||||
func ParamID(r router.ValidatedParamRoute, ctx *router.Context) int64 {
|
||||
return ctx.Value(paramsKey).(int64)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue