Great follow-up! You’re right to question that — idiomatic Go tends to discourage “god packages” or catch-all shared packages just to hold types without good reason.
Let me clarify the nuance here:
In Go, code organization is about logical ownership and minimizing unnecessary dependencies. The key is ownership of types rather than merely grouping by reuse.
When is a shared models or types package a good idea?
- When types truly are domain models or core data structures that logically belong to your entire application or a large subsystem.
- When your APIs share a common domain concept, e.g., a
User or Order struct independent of APIs, and both APIs produce or consume those same domain entities.
When is it not idiomatic?
- When these types are strictly tied to external API schemas or protocol-level details that are only relevant to those API clients.
- When creating a shared package just to avoid duplicate types results in circular dependencies or awkward coupling.
- When types are unlikely to be reused outside a single API client package.
In your case: Two APIs with identical JSON response schemas, but separate packages
The question: Are those JSON types part of your shared domain model or strictly response DTOs?
If those types represent the external API response format (DTOs), idiomatic Go practice often is:
- Keep the types local to each API client package.
- If the schema is identical, you can copy the structs or define them per package.
- Then, transform/copy data to a shared domain type, if applicable, in a higher-level package or service layer.
Why? Because API response types tend to be unstable, tied to external contracts, and can evolve differently for each API; this reduces coupling.
Example layout applying idiomatic approach
/your_project
/api1
client.go
dto.go // types specific to API 1 responses
/api2
client.go
dto.go // types specific to API 2 responses
/domain
entities.go // shared domain types your app uses internally
Both APIs parse their own dto types, then convert those to your internal domain types.
Summary
| Approach | When to use | Idiomatic? |
|---|
Shared models package | Shared domain types | Yes |
| Separate API packages with duplicated DTOs, then convert to domain types | API response/request DTOs | Yes, preferred in many cases |
| Shared package just to hold duplicated JSON response structs | Just to avoid type duplication | Usually discouraged |
Final recommendation for you
- If your APIs are truly independent external services, keep API DTOs local to each package.
- Define a shared domain type in a separate package if you want to unify processing internally.
- Convert API-specific types → domain types via mapping functions.
This keeps your dependencies clean, your code decoupled, and aligns with typical Go project layouts.
If you want, I can help you sketch an example of this approach!