Update Go module path from forge.lthn.ai/core/go-forge to dappco.re/go/core/forge. Migrate all import paths and dependency references (go-io → dappco.re/go/core/io, go-log → dappco.re/go/core/log). Update documentation (CLAUDE.md, README.md, docs/) to reflect new paths. Co-Authored-By: Virgil <virgil@lethean.io>
3.8 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Overview
Full-coverage Go client for the Forgejo API (~450 endpoints). Uses a generic Resource[T,C,U] pattern for CRUD operations and types generated from swagger.v1.json.
Module: dappco.re/go/core/forge (Go 1.26, depends on go-io and go-log)
Build & Test
go test ./... # Run all tests
go test -v -run TestName ./... # Run single test
go generate ./types/... # Regenerate types from swagger spec
go run ./cmd/forgegen/ -spec testdata/swagger.v1.json -out types/ # Manual codegen
No linter or formatter is configured beyond standard go vet.
Architecture
The library is a flat package (package forge) with a layered design:
-
client.go— Low-level HTTP client (Client). All requests go throughdoJSON(). Handles auth (token header), JSON marshalling, rate-limit tracking, and error parsing into*APIError. Also providesGetRaw/PostRawfor non-JSON responses. -
resource.go— GenericResource[T, C, U]struct (T=response type, C=create options, U=update options). Provides List, ListAll, Iter, Get, Create, Update, Delete. Covers ~91% of endpoints. -
pagination.go— GenericListPage[T],ListAll[T],ListIter[T]functions. UsesX-Total-Countheader for pagination.ListIterreturnsiter.Seq2[T, error]for Go 1.26 range-over-func. -
params.go—Paramsmap type andResolvePath()for substituting{placeholders}in API paths. -
config.go— Config resolution: flags > env (FORGE_URL,FORGE_TOKEN) > defaults (http://localhost:3000). -
forge.go— Top-levelForgestruct aggregating all 18 service fields. Created viaNewForge(url, token)orNewForgeFromConfig(flagURL, flagToken). -
Service files (
repos.go,issues.go, etc.) — Each service struct embedsResource[T,C,U]for standard CRUD, then adds hand-written action methods (e.g.Fork,Pin,MirrorSync). 18 services total: repos, issues, pulls, orgs, users, teams, admin, branches, releases, labels, webhooks, notifications, packages, actions, contents, wiki, commits, misc. -
types/— Generated Go types fromswagger.v1.json(229 types). The//go:generatedirective lives intypes/generate.go. Do not hand-edit generated type files — modifycmd/forgegen/instead. -
cmd/forgegen/— Code generator: parses swagger spec (parser.go), extracts types and CRUD pairs, generates Go files (generator.go).
Test Patterns
- Tests use
httptest.NewServerwith inline handlers — no mocks or external services - Test naming uses
_Good,_Bad,_Uglysuffixes (happy path, expected errors, edge cases/panics) - Service-level tests live in
*_test.gofiles alongside each service
Coding Standards
- All methods accept
context.Contextas first parameter - Errors wrapped as
*APIErrorwith StatusCode, Message, URL; useIsNotFound(),IsForbidden(),IsConflict()helpers - Internal errors use
coreerr.E()fromgo-log(imported ascoreerr "dappco.re/go/core/log"), neverfmt.Errorforerrors.New - File I/O uses
go-io(imported ascoreio "dappco.re/go/core/io"), neveros.ReadFile/os.WriteFile/os.MkdirAll - UK English in comments (organisation, colour, etc.)
Co-Authored-By: Virgil <virgil@lethean.io>in commitsClientuses functional options pattern (WithHTTPClient,WithUserAgent)
Adding a New Service
- Create
newservice.gowith a struct embeddingResource[T, C, U] - Add action methods that call
s.client.Get/Post/Patch/Put/Deletedirectly - Wire it into
Forgestruct inforge.goandNewForge() - Add tests in
newservice_test.go
Forge Remote
git remote add forge ssh://git@forge.lthn.ai:2223/core/go-forge.git