You can do this with a union interface and generics.
// Declare a type which is both cats and dogstype pettype interface { cattype | dogtype}// Declare AnimalCount using the union type.type AnimalCount[T pettype] struct { category Animaltype subcategory map[T]int32}func main() { // Instantiate AnimalCount with a concrete type. dc := AnimalCount[dogtype]{category: dogs, subcategory: map[dogtype]int32{retriever: 2, whippet: 4}} cc := AnimalCount[cattype]{category: cats, subcategory: map[cattype]int32{siamese: 5, tabby: 10}} fmt.Println("{}", dc) fmt.Println("{}", cc)}