majiayu000/spellbook / skills/golang-web
golang-web
UnverifiedModern Go Web application architecture guide. Use when creating new Go web projects, APIs, or microservices. Covers project structure, tech stack selection, and best practices based on Go standards.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 10.9 KB |
| reference/architecture.md | markdown | 12.2 KB |
| reference/patterns.md | markdown | 11.8 KB |
| reference/tech-stack.md | markdown | 10.4 KB |
| templates/project/Makefile | other | 2.1 KB |
| templates/project/cmd/myapp/main.go | script | 1.3 KB |
| templates/project/config.yaml | config | 582 B |
| templates/project/configs/config.go | script | 2.1 KB |
| templates/project/go.mod | manifest | 235 B |
| templates/project/internal/handlers/user.go | script | 1.7 KB |
| templates/project/internal/models/user.go | script | 496 B |
| templates/project/internal/repositories/user.go | script | 1.6 KB |
| templates/project/internal/router/router.go | script | 823 B |
| templates/project/internal/services/user.go | script | 2.9 KB |
| templates/project/pkg/database/database.go | script | 1.5 KB |
| templates/project/pkg/errors/errors.go | script | 1.7 KB |
| templates/project/pkg/response/response.go | script | 1.9 KB |
| templates/project/pkg/server/server.go | script | 2.1 KB |
templates/project/pkg/errors/errors.go
View on GitHub// pkg/errors/errors.go
package errors
import "fmt"
// AppError represents an application error with code and message
type AppError struct {
Code int `json:"code"`
Message string `json:"message"`
Cause error `json:"-"`
}
func (e *AppError) Error() string {
if e.Cause != nil {
return fmt.Sprintf("%s: %v", e.Message, e.Cause)
}
return e.Message
}
func (e *AppError) Unwrap() error {
return e.Cause
}
// HTTPStatus returns the HTTP status code for this error
func (e *AppError) HTTPStatus() int {
switch {
case e.Code >= 500:
return 500
case e.Code >= 400:
return e.Code
default:
return 500
}
}
// New creates a new AppError
func New(code int, message string) *AppError {
return &AppError{
Code: code,
Message: message,
}
}
// Wrap wraps an existing error with additional context
func Wrap(err error, code int, message string) *AppError {
if err == nil {
return nil
}
return &AppError{
Code: code,
Message: message,
Cause: err,
}
}
// Wrapf wraps an error with formatted message
func Wrapf(err error, code int, format string, args ...interface{}) *AppError {
if err == nil {
return nil
}
return &AppError{
Code: code,
Message: fmt.Sprintf(format, args...),
Cause: err,
}
}
// Predefined errors
var (
ErrInternal = New(500, "internal server error")
ErrInvalidParams = New(400, "invalid parameters")
ErrNotFound = New(404, "resource not found")
ErrUnauthorized = New(401, "unauthorized")
ErrForbidden = New(403, "forbidden")
ErrConflict = New(409, "resource already exists")
)
// Specific errors
var (
ErrUserNotFound = New(404, "user not found")
ErrUserExists = New(409, "user already exists")
ErrInvalidToken = New(401, "invalid token")
)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |