controller and API setup and basic patterns. Use when you need controller permissions, controller post data, controller params and queries, or setup a new controller or API route
/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.
Controller handler functions follow a standardized pattern with consistent return types and error handling.
All handler functions use this signature:
func handlerName(_ http.ResponseWriter, req *http.Request) (*ModelType, int, error)
Parameters:
_ - ResponseWriter (unused, handled by wrapper)req - HTTP request with context, params, and bodyReturns:
*ModelType/ResponseDataType - The response data (nil on error)int - HTTP status code (200, 400, 404, etc.)error - Error object (nil on success)func adminGet(_ http.ResponseWriter, req *http.Request) (*account.AccountJoined, int, error) {
// Get the URL parameter
id := chi.URLParam(req, "id")
// Fetch the model using the repository pattern
accountObj, err := account.GetJoined(req.Context(), types.UUID(id))
if err != nil {
log.ErrorContext(err, req.Context())
return helpers.AdminBadRequestError[*account.AccountJoined](err)
}
// Return success with the model data
return helpers.Success(accountObj)
}
return helpers.Success(data)
Returns: (data, http.StatusOK, nil)
For admin endpoints - returns full error details:
// Bad request with error message
return helpers.AdminBadRequestError[*ModelType](err)
// Returns: (zeroValue, http.StatusBadRequest, err)
// Not found
return helpers.AdminNotFoundError[*ModelType]()
// Returns: (zeroValue, http.StatusNotFound, standardError)
// Forbidden
return helpers.AdminForbiddenError[*ModelType]()
// Returns: (zeroValue, http.StatusForbidden, standardError)
For public endpoints - returns sanitized error messages:
// Bad request (generic public error)
return helpers.PublicBadRequestError[*ModelType]()
// Returns: (zeroValue, http.StatusBadRequest, publicError)
// Not found
return helpers.PublicNotFoundError[*ModelType]()
// Returns: (zeroValue, http.StatusNotFound, publicError)
// Forbidden
return helpers.PublicForbiddenError[*ModelType]()
// Returns: (zeroValue, http.StatusForbidden, publicError)
Important: Public errors never expose internal error details to users.
// Get URL parameter from route like /account/{id}
id := chi.URLParam(req, "id")
name := chi.URLParam(req, "name")
// Get the current user session (available in all authenticated endpoints)
userSession := helpers.GetReqSession(req) // returns a session object
userObj := helpers.GetLoadedUser(req) // returns the actual user object, not a session wrap
// For POST/PUT endpoints that are not the standard crud, use a struct for the input
input := &MyPostData{}
err := router.GetJSONPostDataStruct(req,input)
doSomething(input.SomeDataHere)
// Access query string parameters
queryParams := req.URL.Query()
page := queryParams.Get("page")
limit := queryParams.Get("limit")
// embeeded route params
id := chi.URLParam(req, "id")
Always log errors with the context before returning up. The controller is the log point.
if err != nil {
log.ErrorContext(err, req.Context())
return helpers.AdminBadRequestError[*ModelType](err)
}
This ensures errors are captured in logs with full request context.
Handlers are wrapped in setup.go:
// Admin endpoint - shows full errors
helpers.RoleHandler(helpers.RoleHandlerMap{
constants.ROLE_ADMIN: response.StandardRequestWrapper(adminCreate),
})
// Public endpoint - sanitizes errors
helpers.RoleHandler(helpers.RoleHandlerMap{
constants.ROLE_ANY_AUTHORIZED: response.StandardPublicRequestWrapper(authGet),
})
For admin endpoints:
response.StandardRequestWrapper(adminHandler)
Features:
For public/authenticated user endpoints:
response.StandardPublicRequestWrapper(authHandler)
Features:
public:"view" tagspublic:"edit" tagsUse appropriate wrappers: Admin handlers with StandardRequestWrapper, public handlers with StandardPublicRequestWrapper
Verify ownership: In auth handlers, always verify the user owns the resource:
if accountObj.ID_.Get() != session.AccountID {
return helpers.PublicForbiddenError[*account.Account]()
}
Principle of least privilege: Use the lowest role required for each endpoint
Don't mix admin and public logic: Keep admin and auth handlers separate
This 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.