This project is a tiny Go HTTP server used as a template for building services that connect to a MariaDB database. The Agents (e.g. code‑generation or review bots) rely on this file for
- build, lint, and test instructions
- coding‑style rules that all authors must obey
- any cursor or Copilot configuration that might exist
The file is intentionally ~150 lines to be readable on both terminal and browser views.
| Action | Command | Notes |
|---|---|---|
| Build | go build |
Builds the binary with default tags. On a CI system this is usually sufficient. |
| Run unit tests | go test ./... |
Executes all tests in every package. |
| Run a single test | go test -run TestName ./... |
Replace TestName with the regexp of the test you want. Example: go test -run TestHealth ./... |
| Lint | golangci-lint run |
Enforces formatting, naming, and most common Go anti‑patterns. |
| Format | go fmt ./... && go vet ./... |
Checks code formatting and static analysis. |
| CI friendly | go test -v ./... && golangci-lint run |
Verbose output good for CI logs. |
- Go >= 1.24.2 (see
go.mod) - golangci‑lint – install via
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
The goal is to keep the codebase small, readable, and idiomatic. All changes should pass the lint and format checks.
- Imports are grouped in three sections by a blank line: standard library, third‑party packages, then local packages.
- Within each group the packages are alphabetically sorted.
- No
dotimports – they are disallowed. - Wildcard imports (e.g.
import "strconv") are prohibited.
import (
"context"
"database/sql"
"fmt"
"log"
"net/http"
"os"
"github.com/go-sql-driver/mysql"
"github.com/gorilla/mux"
"github.com/mmontes11/opencode-test/db"
"github.com/mmontes11/opencode-test/handler"
)- Use
go fmt– it is the de‑facto formatter. - Line length should not exceed 100 characters; a warning will be raised by golangci‑lint.
- Indentation uses tabs, 4 spaces per level.
- Types: PascalCase (
HealthCheckResponse). - Functions:
exportedNameorunexportedName– no prefix likenewormakeunless it conveys intent. - Variables/constants: camelCase for locals, UPPER_SNAKE for package‑const.
- Error return values: always use the idiomatic
if err != nil {}pattern.
- All errors are returned to the caller unless they are truly unrecoverable (e.g.
panic). - Use
fmt.Errorf("context: %w", err)to add context and wrap errors. - Log errors with sufficient detail (
log.Printf("db init failed: %v", err)). - Avoid silent failures – the HTTP health endpoint must return an error status if the DB ping fails.
- When opening a DB, use
context.Background()or the background context from the main function. - For long‑running requests (future extension), propagate context to handlers.
- All tests live next to the file they exercise, under the same package.
- Table‑driven tests for different error scenarios.
- Use
testing.Tfor assertions, no third‑party testing libs. - If a test relies on a database, use a mock or a test container – do not hit a real DB in unit tests.
- All external libs are listed in
go.mod; the build requires no additional binaries.
No Cursor rules are defined in the repository.
No Copilot instructions are present.
If you wish to add rules, create a .cursor/rules/*.json file or .github/copilot-instructions.md. Place the file in the repository root or the suggested location. The rules should be JSON‑formatted and will be parsed by the relevant tooling.
# Build
$ go build -o bin/server
# Run tests (all packages)
$ go test ./...
# Run only the health test (example)
$ go test -run TestHealth ./...
# Check linting
$ golangci-lint runNote: All commands above should be run from the repository root (/home/martin/code/opencode-test).
Author: This file was autogenerated by the Project Agent on 2026‑02‑15. Feel free to adjust any guidelines to fit your team's style.