Skip to content

Instantly share code, notes, and snippets.

Last active Aug 6, 2019
What would you like to do?
import "fmt"
type Other struct {
c bool
x, y int
type Model interface{}
type A struct {
x int
type B struct {
y int
func NewModel(other *Other) Model {
if other.c {
return &A{x: other.x,}
} else {
return &B{
A: A{x: other.x,},
y: other.y,
func test(model Model) {
if a, ok := model.(*A); ok {
fmt.Printf("x: %v", a.x)
} else {
b := model.(*B)
fmt.Printf("x: %v, y: %v", b.x, b.y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment