Windsurf rules for Go backends: standard module layout, Go 1.22+ ServeMux routing with PathValue, wrapped sentinel errors, JSON responses and consumer-side interfaces.
.devin/rules/go-backend-development-for-windsurf.md. Downloaded files need to be placed in that repository path.---
trigger: glob
globs: "**/*"
---
Apply these rules to Go backend code.
## Project layout
```
cmd/
server/
main.go # wiring: config, logger, dependencies, http.Server
internal/
handler/ # HTTP transport
service/ # business logic
repository/ # storage
go.mod
```
- Keep packages that other modules must not import under `internal/`. Add `pkg/` only if the module deliberately publishes reusable packages.
## Routing and handlers (Go 1.22+)
```go
package handler
import (
"encoding/json"
"errors"
"log/slog"
"net/http"
"example.com/app/internal/service"
)
type Handler struct {
users *service.UserService
log *slog.Logger
}
func (h *Handler) Routes(mux *http.ServeMux) {
mux.HandleFunc("GET /users/{id}", h.GetUser)
}
func (h *Handler) GetUser(w http.ResponseWriter, r *http.Request) {
user, err := h.users.Get(r.Context(), r.PathValue("id"))
if errors.Is(err, service.ErrNotFound) {
http.Error(w, "not found", http.StatusNotFound)
return
}
if err != nil {
h.log.ErrorContext(r.Context(), "get user", "err", err)
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(user); err != nil {
h.log.ErrorContext(r.Context(), "encode response", "err", err)
}
}
```
- `r.PathValue` only returns values for wildcards registered in the pattern (`{id}`), which needs `go 1.22` or later in `go.mod`.
- Set `Content-Type` before writing the body and handle encoding errors.
## Error handling
```go
package service
import (
"context"
"errors"
"fmt"
)
var ErrNotFound = errors.New("not found")
func (s *UserService) Get(ctx context.Context, id string) (*User, error) {
user, err := s.repo.Find(ctx, id)
if err != nil {
return nil, fmt.Errorf("get user %s: %w", id, err)
}
return user, nil
}
```
- The repository returns `ErrNotFound` (or wraps it) when no row exists, so `errors.Is` works through the `%w` chain.
## Interfaces
```go
// Defined in the service package, where it is consumed
type UserRepository interface {
Find(ctx context.Context, id string) (*User, error)
Create(ctx context.Context, user *User) error
}
```
## Server
- Set `ReadHeaderTimeout`, `ReadTimeout`, `WriteTimeout` and `IdleTimeout` on `http.Server`, and call `Shutdown` on SIGTERM.
- Run `gofmt`, `go vet` and `go test -race ./...` before proposing changes.
Cursor rule for FastAPI projects using Pydantic v2 schemas, SQLAlchemy 2 async_sessionmaker, lifespan cleanup, explicit commits and 409 conflict handling.
Cursor rule for Express 5 APIs in TypeScript with createApp structure, no try/catch boilerplate, Zod 4 validation into res.locals and a safe central error handler.
Cursor rule for Next.js Route Handlers with Zod 4 safeParse validation, auth and ownership checks, awaited params, bounded pagination and one consistent JSON error shape.
Windsurf
backend
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A Windsurf workspace's Go service calls r.PathValue("id") but registers the route as mux.HandleFunc("/users/", ...), so id is always empty; the error file imports fmt but not errors.
Fix internal/handler/user.go and internal/service/user.go following the Go backend rule (go.mod says go 1.27).
The route is registered as "GET /users/{id}", missing imports (errors, encoding/json, log/slog) are added, ErrNotFound lives in the service package and is matched with errors.Is through %w wrapping, responses set Content-Type and log encode errors, and the answer lists gofmt, go vet and go test -race.Windsurf's rules documentation (docs.windsurf.com/windsurf/cascade/memories) now redirects to Devin documentation, which describes rules for the Devin Local agent in Devin Desktop. Current rules live in .devin/rules/*.md with a trigger setting, and the legacy Windsurf files (.windsurf/rules/*.md, .windsurf/global_rules.md and .windsurfrules) are still imported by default. AGENTS.md files are read as always-on rules.
.devin/rules/go-backend-development-for-windsurf.mdStarting point, not a tested configuration for your repository. Applied when files matching globs are involved (trigger: glob). Review the instructions, adapt the file paths and run your project's existing checks.
---
trigger: glob
globs: "**/*"
---
Apply these rules to Go backend code.
## Project layout
```
cmd/
server/
main.go # wiring: config, logger, dependencies, http.Server
internal/
handler/ # HTTP transport
service/ # business logic
repository/ # storage
go.mod
```
- Keep packages that other modules must not import under `internal/`. Add `pkg/` only if the module deliberately publishes reusable packages.
## Routing and handlers (Go 1.22+)
```go
package handler
import (
"encoding/json"
"errors"
"log/slog"
"net/http"
"example.com/app/internal/service"
)
type Handler struct {
users *service.UserService
log *slog.Logger
}
func (h *Handler) Routes(mux *http.ServeMux) {
mux.HandleFunc("GET /users/{id}", h.GetUser)
}
func (h *Handler) GetUser(w http.ResponseWriter, r *http.Request) {
user, err := h.users.Get(r.Context(), r.PathValue("id"))
if errors.Is(err, service.ErrNotFound) {
http.Error(w, "not found", http.StatusNotFound)
return
}
if err != nil {
h.log.ErrorContext(r.Context(), "get user", "err", err)
http.Error(w, "internal error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(user); err != nil {
h.log.ErrorContext(r.Context(), "encode response", "err", err)
}
}
```
- `r.PathValue` only returns values for wildcards registered in the pattern (`{id}`), which needs `go 1.22` or later in `go.mod`.
- Set `Content-Type` before writing the body and handle encoding errors.
## Error handling
```go
package service
import (
"context"
"errors"
"fmt"
)
var ErrNotFound = errors.New("not found")
func (s *UserService) Get(ctx context.Context, id string) (*User, error) {
user, err := s.repo.Find(ctx, id)
if err != nil {
return nil, fmt.Errorf("get user %s: %w", id, err)
}
return user, nil
}
```
- The repository returns `ErrNotFound` (or wraps it) when no row exists, so `errors.Is` works through the `%w` chain.
## Interfaces
```go
// Defined in the service package, where it is consumed
type UserRepository interface {
Find(ctx context.Context, id string) (*User, error)
Create(ctx context.Context, user *User) error
}
```
## Server
- Set `ReadHeaderTimeout`, `ReadTimeout`, `WriteTimeout` and `IdleTimeout` on `http.Server`, and call `Shutdown` on SIGTERM.
- Run `gofmt`, `go vet` and `go test -race ./...` before proposing changes.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
The docs recommend keeping rules short and specific. The current docs say AGENTS.md, AGENTS.local.md and AGENT.md are read as always-on rules, including files in subdirectories. Use .devin/rules/ when you need glob, model-decision or manual triggers.
Documentation checked 2026-11-05: Devin docs: Local customizations (redirect target of Windsurf memories docs)Windsurf docs: Cascade memories (redirects)
Cursor rule for FastAPI projects using Pydantic v2 schemas, SQLAlchemy 2 async_sessionmaker, lifespan cleanup, explicit commits and 409 conflict handling.
Cursor rule for Express 5 APIs in TypeScript with createApp structure, no try/catch boilerplate, Zod 4 validation into res.locals and a safe central error handler.
Cursor rule for Next.js Route Handlers with Zod 4 safeParse validation, auth and ownership checks, awaited params, bounded pagination and one consistent JSON error shape.