style(go): add rule against type-only packages (per upaas #126 review) #2
@ -238,6 +238,20 @@ last_modified: 2026-02-22
|
|||||||
packages need the same type, put it in the package that owns the behavior,
|
packages need the same type, put it in the package that owns the behavior,
|
||||||
or in a small, focused interface package — not in a grab-bag types package.
|
or in a small, focused interface package — not in a grab-bag types package.
|
||||||
|
|
||||||
|
1. When defining custom string-based types (e.g. `type ImageID string`),
|
||||||
|
implement `fmt.Stringer`. Use `.String()` at SDK and library boundaries
|
||||||
|
instead of `string(v)`. This makes type conversions explicit, grep-able,
|
||||||
|
and consistent across the codebase. Example:
|
||||||
|
|
||||||
|
```go
|
||||||
|
type ContainerID string
|
||||||
|
|
||||||
|
func (id ContainerID) String() string { return string(id) }
|
||||||
|
|
||||||
|
// At the Docker SDK boundary:
|
||||||
|
resp, err := c.docker.ContainerStart(ctx, id.String(), opts)
|
||||||
|
```
|
||||||
|
|
||||||
1. Define your interface types near the functions that use them, or if you have
|
1. Define your interface types near the functions that use them, or if you have
|
||||||
multiple conformant types, put the interface(s) in their own file.
|
multiple conformant types, put the interface(s) in their own file.
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user