gin context util + doc fix
This commit is contained in:
parent
f159014374
commit
a7edae9113
3 changed files with 34 additions and 1 deletions
32
pkg/utils/ginContext.go
Normal file
32
pkg/utils/ginContext.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type contextUtil interface {
|
||||
GetUserUuidFromContext(c *gin.Context) (string, error)
|
||||
}
|
||||
|
||||
func (h *Handler) GetUserUuidFromContext(c *gin.Context) (string, error) {
|
||||
if c == nil {
|
||||
return "", errors.New("context is nil")
|
||||
}
|
||||
|
||||
uuidRaw, exists := c.Get("userUuid")
|
||||
if !exists {
|
||||
return "", errors.New("user uuid not found in context")
|
||||
}
|
||||
|
||||
userUuidStr, ok := uuidRaw.(string)
|
||||
if !ok {
|
||||
return "", errors.New("user uuid is not a string")
|
||||
}
|
||||
|
||||
if err := uuid.Validate(userUuidStr); err != nil {
|
||||
return "", errors.New("error validating user uuid")
|
||||
}
|
||||
return userUuidStr, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue