Skip to content

OneOf method generates useless code? #3597

Answered by douglaswth
antipopp asked this question in Q&A
Discussion options

You must be logged in to vote

A pointer to the Report type can be assigned to the Forms field of the Data type since it implements the interface:

data := &gen.Data{
    Forms: &gen.Report{
        WorkspaceID: "abcdef",
        Assets: []string{"a", "b", "c"},
        From: "a",
        To: "b",
    },
}

On the other side, a type switch (or a checked type assertion) can be used to determine which type a value in the Forms field of the Data type is:

switch forms := data.Forms.(type) {
case *gen.Report:
    fmt.Println(forms.WorkspaceID, forms.Assets, forms.From, forms.To)
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by antipopp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants