Remove some duplication in API handlers

This commit is contained in:
eikendev 2020-08-02 17:31:41 +02:00
parent 018ce2e537
commit a5418d9698
No known key found for this signature in database
GPG key ID: A1BDB1B28C8EF694
5 changed files with 66 additions and 54 deletions

View file

@ -1,9 +1,6 @@
package api
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
)
@ -23,14 +20,3 @@ func RequireIDInURI() gin.HandlerFunc {
ctx.Set("id", requestModel.ID)
}
}
func getID(ctx *gin.Context) (uint, error) {
id, ok := ctx.MustGet("user").(uint)
if !ok {
err := errors.New("an error occured while retrieving ID from context")
ctx.AbortWithError(http.StatusInternalServerError, err)
return 0, err
}
return id, nil
}