Hello,
I'm unfamiliar on how I should solve this in go.
I receive what I am calling Metadata over http in my handler. I receive the body and decode / unmarshal it into a request DTO something like
type MetadataRequest struct { // generic metadata fields like createdAt etc. flavoredMetadata json.RawMessage }
As you can see, Metadata can be in various flavors from various sources. Ultimately it is all Metadata, just that metadata might be in a different shape and have different data depending on the source.
I want to unmarshal the flavoredMetadata into a type specific flavor like:
type RedMetadata struct { // red metadata specific fields + generic metadata fields } type BlueMetadata struct { // blue metadata specific fields + generic metadata fields }
In other languages, I would typically have BlueMetadata and RedMetadata implement an interface of a common type like Metadata, so maybe they both have a Validate method
type Metadata interface { Validate() error }
So I'd give both RedMetadata and…