Interface — contract of method signatures defining what a type can do. Struct — concrete data layout defining what a type holds.
Interfaces enable polymorphism in Go. Since implementation is implicit, you can create new types that satisfy existing interfaces without modifying the interface definition. This is the foundation of Go's "accept interfaces, return structs" philosophy.
1type Store interface {2 Get(key string) (string, error)3 Set(key, value string) error4}56type MemoryStore struct {7 data map[string]string8}910func (m *MemoryStore) Get(key string) (string, error) {11 v, ok := m.data[key]12 if !ok { return "", errors.New("not found") }13 return v, nil14}15func (m *MemoryStore) Set(k, v string) error {16 m.data[k] = v17 return nil18}
Structs hold the actual fields. You can embed structs for composition, add JSON/DB tags, and define methods. Structs are concrete — the compiler knows their exact memory layout.
When to use:
Common mistakes: