System instructions for Gemini on idiomatic Go backends: wrapped errors, Go 1.22+ ServeMux routing, context propagation, consumer-side interfaces and safe concurrency.
GEMINI.md. Downloaded files need to be placed in that repository path.## Gemini Go Developer
Applies to: **/*
You are assisting with Go backend development. Follow idiomatic Go and the project's existing conventions.
## Principles
- Simplicity over cleverness; explicit over implicit; composition over inheritance.
- Define interfaces where they are consumed, keep them small, and return concrete types.
- Pass `context.Context` as the first parameter of functions that do I/O or may block, and respect cancellation.
- Use the Go version in `go.mod`; do not use language or library features newer than it.
## Errors
```go
var ErrNotFound = errors.New("not found")
func (s *Service) GetUser(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
}
```
- Wrap with `%w` and add what was being done; check with `errors.Is` / `errors.As`, never by comparing strings.
- Handle each error once: either return it (wrapped) or log it, not both.
## HTTP
- On Go 1.22+, register method and path patterns on `http.ServeMux` and read wildcards with `r.PathValue`:
```go
mux := http.NewServeMux()
mux.HandleFunc("GET /users/{id}", h.getUser)
mux.HandleFunc("POST /users", h.createUser)
func (h *Handler) getUser(w http.ResponseWriter, r *http.Request) {
user, err := h.svc.GetUser(r.Context(), r.PathValue("id"))
switch {
case errors.Is(err, ErrNotFound):
http.Error(w, "not found", http.StatusNotFound)
return
case 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 user", "err", err)
}
}
```
- Unmatched methods get `405 Method Not Allowed` automatically; do not hand-write method switches.
- Configure `http.Server` timeouts (`ReadHeaderTimeout`, `ReadTimeout`, `WriteTimeout`, `IdleTimeout`) and shut down gracefully with `Shutdown(ctx)`.
## Interfaces
```go
type UserRepository interface {
Find(ctx context.Context, id string) (*User, error)
Save(ctx context.Context, user *User) error
}
```
## Concurrency
- Use channels to pass ownership of data between goroutines and `sync.Mutex` to protect shared state; keep critical sections short.
- Use `errgroup.WithContext` (golang.org/x/sync/errgroup) to run related work in parallel and cancel the rest on the first error; limit parallelism with `SetLimit`.
- Every goroutine has a clear exit path (context cancellation or channel close). Run tests with `-race`.
## Tooling
- Code must pass `gofmt`, `go vet` and the project's linter; use `log/slog` for structured logging.
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.
Gemini
backend
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
A Go 1.27 service still uses a hand-written ServeHTTP method switch, compares error strings, and launches goroutines without cancellation.
Refactor internal/handler/user.go to use the standard library router and fetch a user's profile and orders in parallel.
Routes registered as "GET /users/{id}" with r.PathValue, errors.Is(err, ErrNotFound) mapped to 404, JSON responses with Content-Type and encode errors logged, an errgroup.WithContext fetching profile and orders concurrently, and a note to run go vet and go test -race.Gemini CLI loads instructional context from GEMINI.md files: a global ~/.gemini/GEMINI.md, files in your workspace directories and their parents, and files discovered in subfolders as the agent works. The file name is configurable, so a project can tell Gemini CLI to read AGENTS.md instead of, or alongside, GEMINI.md. The rules in this directory are written as plain system instructions, so the same text can also be used as a system instruction in Gemini API or Google AI Studio requests.
GEMINI.mdStarting point, not a tested configuration for your repository. GEMINI.md has no file-scoping front matter; add this as a section, or place a GEMINI.md in the relevant subfolder. Review the instructions, adapt the file paths and run your project's existing checks.
## Gemini Go Developer
Applies to: **/*
You are assisting with Go backend development. Follow idiomatic Go and the project's existing conventions.
## Principles
- Simplicity over cleverness; explicit over implicit; composition over inheritance.
- Define interfaces where they are consumed, keep them small, and return concrete types.
- Pass `context.Context` as the first parameter of functions that do I/O or may block, and respect cancellation.
- Use the Go version in `go.mod`; do not use language or library features newer than it.
## Errors
```go
var ErrNotFound = errors.New("not found")
func (s *Service) GetUser(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
}
```
- Wrap with `%w` and add what was being done; check with `errors.Is` / `errors.As`, never by comparing strings.
- Handle each error once: either return it (wrapped) or log it, not both.
## HTTP
- On Go 1.22+, register method and path patterns on `http.ServeMux` and read wildcards with `r.PathValue`:
```go
mux := http.NewServeMux()
mux.HandleFunc("GET /users/{id}", h.getUser)
mux.HandleFunc("POST /users", h.createUser)
func (h *Handler) getUser(w http.ResponseWriter, r *http.Request) {
user, err := h.svc.GetUser(r.Context(), r.PathValue("id"))
switch {
case errors.Is(err, ErrNotFound):
http.Error(w, "not found", http.StatusNotFound)
return
case 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 user", "err", err)
}
}
```
- Unmatched methods get `405 Method Not Allowed` automatically; do not hand-write method switches.
- Configure `http.Server` timeouts (`ReadHeaderTimeout`, `ReadTimeout`, `WriteTimeout`, `IdleTimeout`) and shut down gracefully with `Shutdown(ctx)`.
## Interfaces
```go
type UserRepository interface {
Find(ctx context.Context, id string) (*User, error)
Save(ctx context.Context, user *User) error
}
```
## Concurrency
- Use channels to pass ownership of data between goroutines and `sync.Mutex` to protect shared state; keep critical sections short.
- Use `errgroup.WithContext` (golang.org/x/sync/errgroup) to run related work in parallel and cancel the rest on the first error; limit parallelism with `SetLimit`.
- Every goroutine has a clear exit path (context cancellation or channel close). Run tests with `-race`.
## Tooling
- Code must pass `gofmt`, `go vet` and the project's linter; use `log/slog` for structured logging.
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 Gemini CLI documentation states that Gemini CLI was replaced by Antigravity CLI on June 18, 2026 for unpaid-tier and Google One users. Check which CLI your account uses; Antigravity rules are covered on the Antigravity page. Gemini CLI does not need a separate AGENTS.md mechanism: its context file name is configurable through context.fileName in settings.json (the docs show ["AGENTS.md", "CONTEXT.md", "GEMINI.md"]). Without that setting it looks for GEMINI.md.
Documentation checked 2026-11-05: Gemini CLI docs: GEMINI.md context filesGemini CLI docs: System prompt override
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.