Skip to content

Commit 88e1929

Browse files
authored
Add AGENTS.md with build/test commands and code style guidelines (#527)
Provides coding agent instructions covering: - Build, test, and format commands - Import conventions and vendored dependency usage - Naming conventions (PascalCase exports, uppercase acronyms) - Error handling patterns - Embedding and struct tag conventions Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent 30ab39d commit 88e1929

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# AGENTS.md - Coding Agent Instructions
2+
3+
## Project Overview
4+
5+
Go module (`github.com/appscode/static-assets`) providing static assets (JSON data, images, files) for AppsCode products. Uses Go embed for serving data as `fs.FS`. Module path: `appscode-cloud`. Go version: 1.21+ (CI uses 1.25).
6+
7+
## Build & Test Commands
8+
9+
```bash
10+
# Build all packages
11+
CGO_ENABLED=0 go build -v ./...
12+
13+
# Run all tests
14+
CGO_ENABLED=0 go test -v ./...
15+
16+
# Run a single test
17+
CGO_ENABLED=0 go test -v -run TestName ./path/to/package/...
18+
19+
# Run go vet
20+
go vet ./...
21+
22+
# Format code (uses vendored mod)
23+
hack/fmt.sh api cmd data *.go
24+
# Or manually:
25+
goimports -w <files>
26+
gofmt -s -w <files>
27+
28+
# Publish static assets to S3
29+
make publish
30+
```
31+
32+
All build/test commands require `CGO_ENABLED=0` and `GOFLAGS="-mod=vendor"`.
33+
34+
## Code Style
35+
36+
### Package Names
37+
- Lowercase, single-word: `api`, `staticassets`
38+
- Root package name is `staticassets` (not `static-assets`)
39+
40+
### Imports
41+
- Group stdlib first, then external packages, separated by blank line
42+
- Use vendored dependencies (`-mod=vendor`)
43+
- Import the root module as: `staticassets "github.com/appscode/static-assets"`
44+
- Subpackages: `"github.com/appscode/static-assets/api"`
45+
46+
```go
47+
import (
48+
"encoding/json"
49+
"os"
50+
51+
"github.com/appscode/static-assets/api"
52+
)
53+
```
54+
55+
### Naming
56+
- Exported types/funcs: PascalCase (`Product`, `DownloadReleaseAssets`)
57+
- Unexported: camelCase (`exists`, `repoList`)
58+
- Acronyms kept uppercase: `API`, `URL`, `FS`, `ID` (e.g., `URLRef`, `RepoURL`)
59+
- File names: `snake_case.go` for product data files, `main.go` for commands
60+
61+
### Struct Tags
62+
- Always include JSON tags on struct fields
63+
- Use `omitempty` for optional fields
64+
- Prefer explicit JSON field names: `json:"fieldName"`
65+
66+
### Error Handling
67+
- Use `panic()` only for unrecoverable programmer errors (e.g., failed embed.Sub)
68+
- Return `error` for runtime/IO failures; handle or propagate
69+
- Use `log.Fatalln()` for fatal errors in CLI tools
70+
- Use type-switch on error types for specific handling (see GitHub API errors)
71+
72+
### Embedding
73+
- Use `//go:embed` directives for static data
74+
- Wrap in `fs.FS` via `fs.Sub()` for clean access paths
75+
76+
### General
77+
- Prefer `bytes.Buffer` + `json.NewEncoder` over `json.Marshal` for formatted JSON output
78+
- Use `os.WriteFile` with `0o644` permissions
79+
- Use `0o755` for directories
80+
- Keep functions small and focused
81+
- No comments unless explicitly requested

0 commit comments

Comments
 (0)