init project
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package mycontext
|
||||
|
||||
import (
|
||||
"context"
|
||||
"furtuna-be/internal/constants/role"
|
||||
"furtuna-be/internal/entity"
|
||||
)
|
||||
|
||||
type ContextKey string
|
||||
|
||||
type Context interface {
|
||||
context.Context
|
||||
|
||||
RequestedBy() int64
|
||||
IsSuperAdmin() bool
|
||||
}
|
||||
|
||||
type MyContextImpl struct {
|
||||
context.Context
|
||||
|
||||
requestedBy int64
|
||||
requestID string
|
||||
branchID int64
|
||||
roleID int
|
||||
}
|
||||
|
||||
func (m *MyContextImpl) RequestedBy() int64 {
|
||||
return m.requestedBy
|
||||
}
|
||||
|
||||
func (m *MyContextImpl) IsSuperAdmin() bool {
|
||||
return m.roleID == int(role.SuperAdmin)
|
||||
}
|
||||
|
||||
func NewMyContext(parent context.Context, claims *entity.JWTAuthClaims) (*MyContextImpl, error) {
|
||||
return &MyContextImpl{
|
||||
Context: parent,
|
||||
requestedBy: claims.UserID,
|
||||
branchID: claims.BranchID,
|
||||
roleID: claims.Role,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func NewContext(parent context.Context) *MyContextImpl {
|
||||
return &MyContextImpl{
|
||||
Context: parent,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user