Since I can't use fallthrough in type switch, is there any way to merge the two cases in this code?
switch v := moduleSource.(type) {
case Driver:
dec.Decode(&v)
_, _ = ormInstance.Insert(&v)
case Metric:
dec.Decode(&v)
_, _ = ormInstance.Insert(&v)
default:
fmt.Println("unknown type")
}
The ORM call ormInstance.Insert()
has to have the right struct for it to work.
A list of types are allowed in a type switch, as defined in the Go spec.
switch v := moduleSource.(type) {
case *Driver, *Metric:
// v has the same type as moduleSource
dec.Decode(v)
_, _ = ormInstance.Insert(v)
default:
fmt.Println("unknown type")
}