create a struct with a field of type rune in go

To create a struct with a field of type rune in Go, you simply need to define the field with the rune keyword. Here's an example:

main.go
type Person struct {
    Name  string
    Age   int
    Initial rune
}
71 chars
6 lines

In this example, we have defined a struct called Person with three fields: Name of type string, Age of type int, and Initial of type rune. You can now create variables of this struct type and access their individual fields like this:

main.go
p := Person{Name: "Alice", Age: 30, Initial: 'A'}
fmt.Println(p.Name)    // Outputs: "Alice"
fmt.Println(p.Age)     // Outputs: 30
fmt.Println(p.Initial) // Outputs: 'A'
170 chars
5 lines

Note that the rune type in Go is an alias for int32 and represents a Unicode code point. You can assign a rune value to a variable using single quotes, like 'A'.

related categories

gistlibby LogSnag