Looking for go Answers? Try Ask4KnowledgeBase
Looking for go Keywords? Try Ask4Keywords

Go Anonymous struct


Example

It is possible to create an anonymous struct:

data := struct {
    Number int 
    Text   string
} { 
    42, 
    "Hello world!",
}

Full example:

package main

import (
    "fmt"
)

func main() {
    data := struct {Number int; Text string}{42, "Hello world!"} // anonymous struct
    fmt.Printf("%+v\n", data)
}

play it on playground