Documentation
¶
Index ¶
- Variables
- func ListRoles() []string
- func NewDatabaseError(err error) error
- func NewTransformationError(msg string) error
- func NewValidationError(msg string) error
- type Claims
- func (c Claims) AddRole(resource string, role Role)
- func (c Claims) AsSlice() []string
- func (c Claims) GetEffectiveRole(resource string) (Role, bool)
- func (c Claims) HasAtLeast(resource string, required Role) bool
- func (c Claims) MarshalJSON() ([]byte, error)
- func (c *Claims) UnmarshalJSON(data []byte) error
- type CreateUserParams
- type DatabaseError
- type GetPaginatedUsersParams
- type PaginationMeta
- type Role
- type Session
- type TransformationError
- type UpdateUserByIDParams
- type User
- type UserOAuthParams
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var RoleHierarchy = map[Role]int{ RoleGuest: 0, RoleReadOnly: 10, RoleUser: 20, RoleAuditor: 30, RoleEditor: 40, RoleModerator: 50, RoleSupport: 60, RoleAdmin: 70, RoleOwner: 80, RoleSystemAdmin: 90, }
RoleHierarchy defines the privilege level of each role. Higher numbers represent higher privileges. If you define additional roles, place them in here.
Functions ¶
func ListRoles ¶
func ListRoles() []string
ListRoles returns a slice of all existing roles from the RoleHierarchy with the lowest permission role first and the highest last.
func NewDatabaseError ¶
NewDatabaseError creates a new DatabaseError.
func NewTransformationError ¶
NewTransformationError creates a new TransformationError.
func NewValidationError ¶
NewValidationError creates a new ValidationError with the given message.
Types ¶
type Claims ¶
Claims maps resource paths to roles, representing access permissions.
func (Claims) AsSlice ¶
AsSlice returns the claims as a colon delimited slice of roles eg. "/": "admin", "/admin": "user" -> ["/:admin", "/admin:user"]
func (Claims) GetEffectiveRole ¶
GetEffectiveRole returns the most specific role matching the given resource path. It finds the longest prefix in the Claims map that matches the resource, applying path boundary checks to avoid partial matches (e.g., "/api/" does not match "/api2/"). Returns the matched Role and true if found, or an empty Role and false if no match exists.
func (Claims) HasAtLeast ¶
HasAtLeast reports whether the role for the given resource path meets or exceeds the required Role level. Returns false if no role is found.
func (Claims) MarshalJSON ¶
func (*Claims) UnmarshalJSON ¶
type CreateUserParams ¶
type CreateUserParams struct {
Email string `json:"email"`
Password *string `json:"password"`
Role Role `json:"role"`
Claims Claims `json:"claims"`
OauthProvider *string `json:"oauthProvider"`
OauthID *string `json:"oauthId"`
}
func (*CreateUserParams) Validate ¶
func (c *CreateUserParams) Validate() error
type DatabaseError ¶
type DatabaseError struct {
// contains filtered or unexported fields
}
DatabaseError – for failures interacting with the persistence layer. Supports errors.As and errors.Unwrap.
DatabaseError wraps errors related to database or SQL interactions. Will only be provided as a response from internal stores.
func (*DatabaseError) Error ¶
func (e *DatabaseError) Error() string
Error implements the error interface.
func (*DatabaseError) Unwrap ¶
func (e *DatabaseError) Unwrap() error
type GetPaginatedUsersParams ¶
type GetPaginatedUsersParams struct {
Page int `json:"page"`
Limit int `json:"limit"`
Role *Role `json:"role"`
}
func (*GetPaginatedUsersParams) Validate ¶
func (p *GetPaginatedUsersParams) Validate() error
type PaginationMeta ¶
type Role ¶
type Role string
Role represents a user role in the system
const ( RoleGuest Role = "guest" // very limited access, items you'd only want publically available RoleReadOnly Role = "readonly" // Can view, but perhaps not interact or create RoleUser Role = "user" // standard authenticated user, can usually create and owns their own data RoleAuditor Role = "auditor" // more access than user but usually not allowed to edit RoleEditor Role = "editor" // can edit and modify content but perhaps not users RoleModerator Role = "moderator" // Can moderate content, user content etc RoleSupport Role = "support" // can perform support actions, perhaps can view sensitive data RoleAdmin Role = "admin" // Full administrative control within a scope RoleOwner Role = "owner" // Owner of specific entity, can delegate admins RoleSystemAdmin Role = "sysadmin" // system wide administrator, highest privilege )
These are the standard roles available by default
func (Role) MarshalText ¶
func (Role) String ¶
String implements the fmt.Stringer interface, providing a string representation of the Role.
func (*Role) UnmarshalText ¶
UnmarshalText and MarshalText methods
type Session ¶
type Session struct {
ID string // Unique identifier for the session (e.g., UUID)
UserID uuid.UUID // ID of the user associated with this session
ExpiresAt time.Time // When the session becomes invalid
CreatedAt time.Time // When the session was created
IpAddress *string // Optional ip address
UserAgent *string // Optional UserAgent
}
Session represents the data stored for a single user session.
type TransformationError ¶
type TransformationError struct {
// contains filtered or unexported fields
}
TransformationError – for issues converting generic input into backend-specific formats. Supports errors.As.
TransformationError wraps errors that occur during the transformation of inputs.
func (*TransformationError) Error ¶
func (e *TransformationError) Error() string
Error implements the error interface.
type UpdateUserByIDParams ¶
type UpdateUserByIDParams struct {
ID uuid.UUID `json:"id"`
Email *string `json:"email"`
Password *string `json:"-"`
Role *Role `json:"role"`
Claims *Claims `json:"claims"`
OauthProvider *string `json:"oauthProvider"`
OauthID *string `json:"oauthId"`
IsActive *bool `json:"isActive"`
}
UpdateUserByIDParams is a struct for updating a user Everything is intentionally a pointer to allow for Coalescing at the db level
func (*UpdateUserByIDParams) Verify ¶
func (u *UpdateUserByIDParams) Verify() error
Verify performs validation and transformation on the UpdateUserByIDParams struct. It ensures required fields are present, validates input formats, and hashes the password if provided.
type User ¶
type User struct {
ID uuid.UUID `json:"id"`
Email string `json:"email"`
PasswordHash *string `json:"-"`
Role Role `json:"role"`
Claims Claims `json:"claims"`
OauthProvider *string `json:"oauthProvider"`
OauthID *string `json:"oauthId"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
IsActive bool `json:"isActive"`
}
func (*User) EnsureRootClaim ¶
func (u *User) EnsureRootClaim()
type UserOAuthParams ¶
type ValidationError ¶
type ValidationError struct {
// contains filtered or unexported fields
}
ValidationError – for invalid parameters or business rule violations. Supports errors.As.
ValidationError represents an error due to invalid or malformed input.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface.