moved packages out of pkg
This commit is contained in:
16
internal/contexts/devmode.go
Normal file
16
internal/contexts/devmode.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package contexts
|
||||
|
||||
import "context"
|
||||
|
||||
func DevMode(ctx context.Context) DevInfo {
|
||||
devmode, ok := ctx.Value(DevModeKey).(DevInfo)
|
||||
if !ok {
|
||||
return DevInfo{}
|
||||
}
|
||||
return devmode
|
||||
}
|
||||
|
||||
type DevInfo struct {
|
||||
WebsocketBase string
|
||||
HTMXLog bool
|
||||
}
|
||||
13
internal/contexts/keys.go
Normal file
13
internal/contexts/keys.go
Normal file
@@ -0,0 +1,13 @@
|
||||
// Package contexts provides utilities for loading and extracting structs from contexts
|
||||
package contexts
|
||||
|
||||
type Key string
|
||||
|
||||
func (c Key) String() string {
|
||||
return "oslstats context key " + string(c)
|
||||
}
|
||||
|
||||
var (
|
||||
DevModeKey Key = Key("devmode")
|
||||
PermissionCacheKey Key = Key("permissions")
|
||||
)
|
||||
23
internal/contexts/permissions.go
Normal file
23
internal/contexts/permissions.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package contexts
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.haelnorr.com/h/oslstats/internal/permissions"
|
||||
"git.haelnorr.com/h/oslstats/internal/roles"
|
||||
)
|
||||
|
||||
// Permissions retrieves the permission cache from context (type-safe)
|
||||
func Permissions(ctx context.Context) *PermissionCache {
|
||||
cache, ok := ctx.Value(PermissionCacheKey).(*PermissionCache)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return cache
|
||||
}
|
||||
|
||||
type PermissionCache struct {
|
||||
Permissions map[permissions.Permission]bool
|
||||
Roles map[roles.Role]bool
|
||||
HasWildcard bool
|
||||
}
|
||||
Reference in New Issue
Block a user