@nakedev/go-scaffold 0.1.0 → 0.1.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakedev/go-scaffold",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Scaffold Gin + GORM + Postgres Go backend projects with a consistent domain-module standard",
5
5
  "bin": {
6
6
  "go-scaffold": "./bin/go-scaffold.js"
@@ -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