Controller role handling. Use when you need to setup a api endpoint with the right permissions and roles
/plugin marketplace add griffnb/claude-plugins/plugin install backend@claude-pluginsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
The helpers.RoleHandler function provides role-based access control by mapping roles to specific handler functions.
helpers.RoleHandler(helpers.RoleHandlerMap{
constants.ROLE_READ_ADMIN: response.StandardRequestWrapper(adminGet),
constants.ROLE_ADMIN: response.StandardRequestWrapper(adminCreate),
})
Roles are defined as integer constants in descending order of privilege:
| Role | Value | Description |
|---|---|---|
ROLE_ADMIN | 100 | Full system administrator access |
ROLE_READ_ADMIN | 90 | Read-only administrator access |
ROLE_ANY_AUTHORIZED | 0 | Any authenticated user |
ROLE_UNAUTHORIZED | -1 | Unauthenticated requests |
If a user's role doesn't exactly match a handler, the system checks lower-privilege handlers:
helpers.RoleHandler(helpers.RoleHandlerMap{
constants.ROLE_READ_ADMIN: response.StandardRequestWrapper(adminGet),
constants.ROLE_ANY_AUTHORIZED: response.StandardRequestWrapper(authGet),
})
Examples:
ROLE_ADMIN (100) → Uses ROLE_READ_ADMIN handler (fallback)ROLE_READ_ADMIN (90) → Uses ROLE_READ_ADMIN handler (exact match)ROLE_ANY_AUTHORIZED (0) → Uses ROLE_ANY_AUTHORIZED handler (exact match)The RoleHandler automatically injects the session into the request context, making it available via:
userSession := helpers.GetReqSession(req)
Session Fields:
type Session struct {
User coremodel.Model // thin wrapper over session data if you only need the users ID, i.e. sessionObj.User.ID(), or used to save data so we can track who saved it.
LoadedUser any // fully loaded user from the database, dont access directly, use the helper.GetLoadedUser(req)
}
Full admin access required:
r.Post("/", helpers.RoleHandler(helpers.RoleHandlerMap{
constants.ROLE_ADMIN: response.StandardRequestWrapper(adminCreate),
}))
r.Put("/{id}", helpers.RoleHandler(helpers.RoleHandlerMap{
constants.ROLE_ADMIN: response.StandardRequestWrapper(adminUpdate),
}))
r.Delete("/{id}", helpers.RoleHandler(helpers.RoleHandlerMap{
constants.ROLE_ADMIN: response.StandardRequestWrapper(adminDelete),
}))
Both full admins and read-only admins can access:
r.Get("/", helpers.RoleHandler(helpers.RoleHandlerMap{
constants.ROLE_READ_ADMIN: response.StandardRequestWrapper(adminIndex),
}))
r.Get("/{id}", helpers.RoleHandler(helpers.RoleHandlerMap{
constants.ROLE_READ_ADMIN: response.StandardRequestWrapper(adminGet),
}))
r.Get("/count", helpers.RoleHandler(helpers.RoleHandlerMap{
constants.ROLE_READ_ADMIN: response.StandardRequestWrapper(adminCount),
}))
Any authenticated user can access:
r.Get("/", helpers.RoleHandler(helpers.RoleHandlerMap{
constants.ROLE_ANY_AUTHORIZED: response.StandardPublicRequestWrapper(authIndex),
}))
r.Get("/{id}", helpers.RoleHandler(helpers.RoleHandlerMap{
constants.ROLE_ANY_AUTHORIZED: response.StandardPublicRequestWrapper(authGet),
}))
Different handlers for different roles on the same route:
r.Get("/{id}", helpers.RoleHandler(helpers.RoleHandlerMap{
constants.ROLE_ADMIN: response.StandardRequestWrapper(adminGetFull),
constants.ROLE_ANY_AUTHORIZED: response.StandardPublicRequestWrapper(authGetLimited),
}))
Example:
adminGetFullauthGetLimitedThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.