0003: Struct Tags Are Reflection-Driven Metadata
Date: 2026-06-14 Status: Accepted
Context
Learner has completed interfaces (0001) and error handling (0002). The next skill needed for cloud-native contribution is understanding how Go drives serialization, validation, and code generation via struct tags. Kubernetes CRDs, gRPC/protobuf services, and config binding all depend on tags.
Insight
Struct tags are not magic — they're a convention. The encoding/json package uses reflect to read tag strings at runtime. Third-party libraries do the same. Teaching tags as a bridge to reflection (Lesson 0010) makes the progression feel natural: "you've been using reflection through tags this whole time."
The lesson should focus on the tag format (key:"value"), the common tag keys (json, protobuf, yaml, validate, env), and how libraries consume them. The hands-on exercises should mirror real cloud-native patterns: JSON serialization with custom field names, omitempty, and protobuf struct tag patterns.
Consequences
- Lesson 0003: Struct tags, JSON encoding/decoding, protobuf tag patterns, custom tag usage
- Should include the
encoding/jsonmarshal/unmarshal cycle as the core skill - The protobuf section should show what
protoc-gen-gogenerates, not teach protobuf schema design - This sets up the reflection lesson (0010) by showing tags as the user-facing side of reflect
- Cheat sheet should be a tag reference table for json, protobuf, yaml, and validate