feat: add getCurrentUserId helper function

This commit is contained in:
Derrick Hammer 2023-06-09 07:38:46 -04:00
parent 40309311bd
commit 29d6db2009
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"git.lumeweb.com/LumeWeb/portal/logger"
"github.com/kataras/iris/v12"
"go.uber.org/zap"
"strconv"
)
func tryParseRequest(r interface{}, ctx iris.Context) (interface{}, bool) {
@ -70,3 +71,16 @@ func (c Controller) respondJSON(data interface{}) {
logger.Get().Error("failed to generate response", zap.Error(err))
}
}
func getCurrentUserId(ctx iris.Context) uint {
usr := ctx.User()
if usr == nil {
return 0
}
sid, _ := usr.GetID()
userID, _ := strconv.Atoi(sid)
return uint(userID)
}