- rbac/: Role type, constants, HasPermission, RoleFromString - blocks/: BlockFunc, BlockMeta, BlockContext, context accessors, BlockRegistry interface - templates/: TemplateFunc, meta types, TemplateRegistry interface - auth/: Claims, PublicClaims, context extractors - content/: Content interface, AuthorProfile/PageInfo/PostInfo types - settings/: Settings interface, map accessor helpers - gating/: AccessRule, AccessResult, EvaluateAccess, Gating interface - crypto/: Crypto interface (Encrypt/Decrypt) - render/: BlockNoteToHTML standalone renderer - video/: ParseEmbedURL, EmbedIframeURL - ai/: ToolDefinition, ToolResult, ToolRegistry interface Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package settings
|
|
|
|
import "context"
|
|
|
|
// Settings provides settings access for plugins.
|
|
type Settings interface {
|
|
GetSiteSettings(ctx context.Context) (map[string]any, error)
|
|
GetPluginSettings(ctx context.Context, pluginName string) (map[string]any, error)
|
|
}
|
|
|
|
// GetStringOr returns a string value from a map, or defaultVal if not found/wrong type.
|
|
func GetStringOr(m map[string]any, key, defaultVal string) string {
|
|
if v, ok := m[key].(string); ok {
|
|
return v
|
|
}
|
|
return defaultVal
|
|
}
|
|
|
|
// GetBoolOr returns a bool value from a map, or defaultVal if not found/wrong type.
|
|
func GetBoolOr(m map[string]any, key string, defaultVal bool) bool {
|
|
if v, ok := m[key].(bool); ok {
|
|
return v
|
|
}
|
|
return defaultVal
|
|
}
|
|
|
|
// GetIntOr returns an int value from a map, handling both int and float64 (JSON numbers).
|
|
func GetIntOr(m map[string]any, key string, defaultVal int) int {
|
|
if v, ok := m[key].(float64); ok {
|
|
return int(v)
|
|
}
|
|
if v, ok := m[key].(int); ok {
|
|
return v
|
|
}
|
|
return defaultVal
|
|
}
|
|
|
|
// GetFloat64Or returns a float64 value from a map, or defaultVal if not found/wrong type.
|
|
func GetFloat64Or(m map[string]any, key string, defaultVal float64) float64 {
|
|
if v, ok := m[key].(float64); ok {
|
|
return v
|
|
}
|
|
return defaultVal
|
|
}
|