mirror of
https://github.com/pushbits/server.git
synced 2025-06-09 14:12:15 +02:00
Remove some duplication in API handlers
This commit is contained in:
parent
018ce2e537
commit
a5418d9698
5 changed files with 66 additions and 54 deletions
19
api/context.go
Normal file
19
api/context.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue