|
| 1 | +# Copilot Instructions |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +Go implementation of [JSON Pointer (RFC 6901)](https://datatracker.ietf.org/doc/html/rfc6901) for navigating |
| 6 | +and mutating JSON documents represented as Go values. Works with `map[string]any`, slices, and Go structs |
| 7 | +(resolved via `json` struct tags and reflection). |
| 8 | + |
| 9 | +## Package Layout (single package) |
| 10 | + |
| 11 | +| File | Contents | |
| 12 | +|------|----------| |
| 13 | +| `pointer.go` | Core types (`Pointer`, `JSONPointable`, `JSONSetable`), `New`, `Get`, `Set`, `Offset`, `Escape`/`Unescape` | |
| 14 | +| `errors.go` | Sentinel errors: `ErrPointer`, `ErrInvalidStart`, `ErrUnsupportedValueType` | |
| 15 | + |
| 16 | +## Key API |
| 17 | + |
| 18 | +- `New(string) (Pointer, error)` — parse a JSON pointer string (e.g. `"/foo/0/bar"`) |
| 19 | +- `Pointer.Get(document any) (any, reflect.Kind, error)` — retrieve a value |
| 20 | +- `Pointer.Set(document, value any) (any, error)` — set a value (document must be pointer/map/slice) |
| 21 | +- `Pointer.Offset(jsonString string) (int64, error)` — byte offset of token in raw JSON |
| 22 | +- `GetForToken` / `SetForToken` — single-level convenience helpers |
| 23 | +- `Escape` / `Unescape` — RFC 6901 token escaping (`~0` ↔ `~`, `~1` ↔ `/`) |
| 24 | + |
| 25 | +Custom types can implement `JSONPointable` (for Get) or `JSONSetable` (for Set) to bypass reflection. |
| 26 | + |
| 27 | +## Design Decisions |
| 28 | + |
| 29 | +- Struct fields **must** have a `json` tag to be reachable; untagged fields are ignored. |
| 30 | +- Anonymous embedded struct fields are traversed only if tagged. |
| 31 | +- The RFC 6901 `"-"` array suffix (append) is **not** implemented. |
| 32 | + |
| 33 | +## Dependencies |
| 34 | + |
| 35 | +- `github.com/go-openapi/swag/jsonname` — struct tag to JSON field name resolution |
| 36 | +- `github.com/go-openapi/testify/v2` — test-only assertions (zero-dep fork of `stretchr/testify`) |
| 37 | + |
| 38 | +## Conventions |
| 39 | + |
| 40 | +- All `.go` files must have SPDX license headers (Apache-2.0). |
| 41 | +- Commits require DCO sign-off (`git commit -s`). |
| 42 | +- Linting: `golangci-lint run` — config in `.golangci.yml` (posture: `default: all` with explicit disables). |
| 43 | +- Every `//nolint` directive **must** have an inline comment explaining why. |
| 44 | +- Tests: `go test ./...` with `-race`. CI runs on `{ubuntu, macos, windows} x {stable, oldstable}`. |
| 45 | +- Test framework: `github.com/go-openapi/testify/v2` (not `stretchr/testify`). |
| 46 | + |
| 47 | +See `.github/copilot/` (symlinked to `.claude/rules/`) for detailed rules on Go conventions, linting, and testing. |
0 commit comments