@nakedev/go-scaffold 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -12,22 +12,26 @@ same shape as the last one.
12
12
  ## Install
13
13
 
14
14
  ```bash
15
- pnpm install
16
- pnpm run build
15
+ npm install -g @nakedev/go-scaffold
17
16
  ```
18
17
 
19
- `npm link` / `pnpm link --global` may not put the binary on your `PATH`
20
- depending on your machine's npm/pnpm global-bin config — rather than fight
21
- that, run the CLI directly, or add a shell alias once:
18
+ Or run it without installing:
19
+
20
+ ```bash
21
+ npx @nakedev/go-scaffold create my-api
22
+ ```
23
+
24
+ Working on the CLI itself (not just using it)? Clone the repo, then:
22
25
 
23
26
  ```bash
27
+ pnpm install
28
+ pnpm run build
24
29
  node bin/go-scaffold.js create my-api --defaults
25
- # or: alias go-scaffold="node $(pwd)/bin/go-scaffold.js"
26
30
  ```
27
31
 
28
- The rest of this README uses the bare `go-scaffold ...` form for brevity
29
- substitute the `node bin/go-scaffold.js ...` form or your alias if you
30
- haven't linked it.
32
+ `npm link` / `pnpm link --global` may not put the binary on your `PATH`
33
+ depending on your machine's npm/pnpm global-bin config running
34
+ `node bin/go-scaffold.js ...` directly sidesteps that.
31
35
 
32
36
  ## Quick start
33
37
 
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@nakedev/go-scaffold",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Scaffold Gin + GORM + Postgres Go backend projects with a consistent domain-module standard",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/NakePranob/go-scaffold.git"
8
+ },
5
9
  "bin": {
6
10
  "go-scaffold": "./bin/go-scaffold.js"
7
11
  },
@@ -7,7 +7,7 @@ PGPASSWORD ?= postgres
7
7
  .PHONY: run build test fmt vet lint tidy db-create db-drop migrate-up migrate-down{{#if openapiDocs}} openapi-bundle{{/if}}{{#if docker}} docker-up docker-down{{/if}}
8
8
 
9
9
  run:
10
- go run ./cmd/api
10
+ @[ -f .env ] && export $$(grep -v '^#' .env | xargs); go run ./cmd/api
11
11
 
12
12
  build:
13
13
  go build -o bin/api ./cmd/api
@@ -38,10 +38,12 @@ make docker-up # local Postgres (postgres:5432)
38
38
  make db-create # create the {{dbName}} database itself (once — safe to re-run)
39
39
  go mod tidy
40
40
  make run # AUTO_MIGRATE=true creates the schema automatically in dev
41
- # or override with env (the app reads os.Getenv directly, see .env.example):
42
- export $(grep -v '^#' .env.example | xargs) && make run
43
41
  ```
44
42
 
43
+ `make run` loads `.env` if present (copy `.env.example` to `.env` to override
44
+ defaults — the app itself just reads `os.Getenv`, no `.env` parsing at
45
+ runtime).
46
+
45
47
  `make db-create` connects to Postgres at `DB_HOST`/`DB_PORT`/`DB_USER` (default:
46
48
  `localhost`/`5432`/`postgres`, matching `.env.example`) using the `psql`
47
49
  client — works the same whether Postgres came from `make docker-up` or an
@@ -86,6 +86,37 @@ if this project has one):
86
86
  pre-check existence before insert; let the DB enforce it atomically and
87
87
  catch the error — a pre-check has a TOCTOU race.
88
88
 
89
+ ## Calling Another Domain's Logic
90
+
91
+ For behavior, not just a data reference (e.g. `order` needs `user`'s email
92
+ to put on a receipt) — the caller's `service.go` declares its own narrow
93
+ interface for exactly what it needs, the same way it already declares a
94
+ `repository` interface:
95
+
96
+ ```go
97
+ // order/service.go
98
+ type userLookup interface {
99
+ GetByID(ctx context.Context, id uuid.UUID) (user.Response, error)
100
+ }
101
+ ```
102
+
103
+ `cmd/api/main.go` wires the concrete `user` service in — it already
104
+ satisfies the interface, no adapter needed:
105
+
106
+ ```go
107
+ userSvc := user.NewService(userRepo)
108
+ orderSvc := order.NewService(orderRepo, userSvc)
109
+ ```
110
+
111
+ - **One direction only.** If `user` would need to call back into `order`,
112
+ don't wire it both ways — either the two belong in one domain, or the
113
+ callback needs an event/queue, not a direct call.
114
+ - **Don't use this to replace a FK check.** Calling `userLookup.GetByID`
115
+ to verify a user exists before inserting an order is the same TOCTOU race
116
+ rule 3 above warns about — let the FK constraint catch it instead. Use
117
+ this pattern only when the caller needs actual data from the other
118
+ domain, not just its existence.
119
+
89
120
  ## Adding One Endpoint — `generate method`
90
121
 
91
122
  ```bash