Go Interfaces

Guides Go interface design and the typed-nil-error gotcha — accept interfaces and return concrete structs, keep interfaces small (1–3 methods, `-er` names), define them on the consumer side not the producer, avoid `any`/`interface{}` as a parameter type, compose with embedding, and never return a concrete `*MyError`/pointer type where the value can be nil. Auto-invokes when writing or editing interface definitions, function signatures that take or return interfaces, `any`/`interface{}` parameters, interface embedding, or functions returning concrete error/pointer types — and on "why is this nil check failing", "is this always non-nil", or "should this be an interface". An interface holds a (type, value) pair, so a nil pointer inside one is not a nil interface.

ctoth 182be5d 3 files · 32.0 KB Updated

File contents

ctoth/golang-skills-plugin/tree/main/plugins/golang/skills/go-interfaces commit 182be5d882

Frequently asked questions

npx skillmds@latest add ctoth/go-interfaces