@nakedev/go-scaffold 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/prompts/create-wizard.js +1 -1
- package/dist/utils/observability-patcher.js +2 -2
- package/package.json +1 -1
- package/templates/create/base/README.md.hbs +3 -3
- package/templates/create/base/cmd/api/wiring.go.hbs +7 -17
- package/templates/create/features/docs/architecture.md.hbs +3 -3
- package/templates/create/features/docs/techstack.md.hbs +1 -1
|
@@ -28,7 +28,7 @@ async function runCreateWizard(preset = {}) {
|
|
|
28
28
|
}));
|
|
29
29
|
const openapiDocs = preset.openapiDocs ??
|
|
30
30
|
(await (0, interactive_1.confirm)({
|
|
31
|
-
message: "Include hand-written OpenAPI docs (docs/openapi.yaml
|
|
31
|
+
message: "Include hand-written OpenAPI docs (docs/openapi.yaml — files only, never served over HTTP)?",
|
|
32
32
|
default: true,
|
|
33
33
|
}));
|
|
34
34
|
const observability = preset.observability ??
|
|
@@ -49,8 +49,8 @@ function patchMainGoForObservability(mainGoPath, goModule, projectName) {
|
|
|
49
49
|
}
|
|
50
50
|
const newUseLine = `${USE_LINE.slice(0, -1)}, middleware.Metrics(), middleware.Tracing("${projectName}"))`;
|
|
51
51
|
content = content.replace(USE_LINE, () => newUseLine);
|
|
52
|
-
//
|
|
53
|
-
// want a scrape target, and Prometheus reaches it in-cluster. It is still
|
|
52
|
+
// Unlike docs/, which is never served at all: production is exactly where
|
|
53
|
+
// you want a scrape target, and Prometheus reaches it in-cluster. It is still
|
|
54
54
|
// unauthenticated and does disclose your route list and traffic shape, so
|
|
55
55
|
// block /metrics at the ingress rather than publishing it to the internet.
|
|
56
56
|
const metricsRoute = 'r.GET("/metrics", gin.WrapH(promhttp.Handler()))';
|
package/package.json
CHANGED
|
@@ -166,15 +166,15 @@ TEST_DB_DSN=postgres://postgres:postgres@localhost:5432/{{dbName}}_test?sslmode=
|
|
|
166
166
|
|
|
167
167
|
## API spec
|
|
168
168
|
|
|
169
|
-
`docs/openapi.yaml` is hand-written and
|
|
169
|
+
`docs/openapi.yaml` is hand-written and split across sibling files (`common/`, `health/`, per-domain folders) via relative `$ref`. **The server never serves it** — there is no `/docs` route, in any environment, so the API surface and `docs/architect/`'s internal notes stay off the wire. Update the spec by hand whenever an endpoint/DTO changes.
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
To open it in a renderer (Scalar, Swagger UI, Redoc) or a client generator (Hey API), bundle it into one fully-resolved file and point the tool at that file. Bundling is also what importers that don't resolve external `$ref`s need — they read the index as-is and see zero routes (Bruno's "Import Collection" does this; some Postman flows too):
|
|
172
172
|
|
|
173
173
|
```bash
|
|
174
174
|
make openapi-bundle # writes docs/openapi.bundled.yaml (gitignored — regenerate anytime)
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
Then open `docs/openapi.bundled.yaml` — it needs no network and no running server.
|
|
178
178
|
{{/if}}
|
|
179
179
|
|
|
180
180
|
## Adding a domain
|
|
@@ -89,23 +89,13 @@ func run() error {
|
|
|
89
89
|
})
|
|
90
90
|
// go-scaffold:extra-routes
|
|
91
91
|
{{#if openapiDocs}}
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
//
|
|
99
|
-
// which reads as "this is broken" rather than "ask for a file". The listing
|
|
100
|
-
// costs nothing here — every file in the tree is already downloadable — and
|
|
101
|
-
// it makes openapi.yaml discoverable without knowing its name up front.
|
|
102
|
-
//
|
|
103
|
-
// Not in production: this serves your whole API surface — every path,
|
|
104
|
-
// parameter and schema — to anyone who asks. Publish the spec deliberately
|
|
105
|
-
// (`make openapi-bundle`) rather than by leaving this on.
|
|
106
|
-
if !cfg.IsProd() {
|
|
107
|
-
r.StaticFS("/docs", gin.Dir("./docs", true))
|
|
108
|
-
}
|
|
92
|
+
// ponytail: docs/ is deliberately NOT served over HTTP, in any environment.
|
|
93
|
+
// The whole tree — every path, parameter and schema, plus docs/architect/'s
|
|
94
|
+
// internal design notes — used to be reachable at /docs outside production.
|
|
95
|
+
// Read the spec from the working copy instead: `make openapi-bundle` writes
|
|
96
|
+
// one fully-resolved docs/openapi.bundled.yaml for a renderer or client
|
|
97
|
+
// generator to open as a local file. Publish it deliberately if you want
|
|
98
|
+
// it public.
|
|
109
99
|
{{/if}}
|
|
110
100
|
|
|
111
101
|
api := r.Group("/{{apiPrefix}}")
|
|
@@ -104,9 +104,9 @@ insert, so it doesn't need `gen_random_uuid()`.
|
|
|
104
104
|
## 8. API Documentation
|
|
105
105
|
|
|
106
106
|
**Decision:** Hand-written OpenAPI spec (`docs/openapi.yaml`), split by
|
|
107
|
-
domain module,
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
domain module, read from the working copy only — the server serves no `/docs`
|
|
108
|
+
route in any environment. Renderers that follow relative `$ref`s get a
|
|
109
|
+
fully-resolved single file from `make openapi-bundle`.
|
|
110
110
|
**Rationale:** Cheap while the endpoint count is low; switch to
|
|
111
111
|
comment-generated (swaggo) if hand-updates start drifting.
|
|
112
112
|
{{/if}}
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
- PostgreSQL + GORM baseline: always enabled
|
|
23
23
|
- Graceful shutdown, structured logging, `/livez` + `/readyz`: always enabled
|
|
24
24
|
- Docker Compose (local Postgres): `{{#if docker}}enabled{{else}}disabled{{/if}}`
|
|
25
|
-
- OpenAPI docs (`docs/openapi.yaml`,
|
|
25
|
+
- OpenAPI docs (`docs/openapi.yaml`, working-copy only — never served over HTTP): `{{#if openapiDocs}}enabled{{else}}disabled{{/if}}`
|
|
26
26
|
- Metrics + tracing (Prometheus `/metrics`, OpenTelemetry for Gin + GORM, `cmd/api` only): `{{#if observability}}enabled{{else}}disabled{{/if}}`
|
|
27
27
|
- API route prefix: `{{#if apiPrefix}}/{{apiPrefix}}{{else}}(none){{/if}}`
|
|
28
28
|
- CI (`.github/workflows/ci.yml` — build, vet, gofmt check, golangci-lint, `go test` with a real Postgres service): always enabled
|