SoFunction
Updated on 2025-03-03

Go language structure definition and usage method

This article describes the definition and usage of Go language structures. Share it for your reference. The specific analysis is as follows:

A struct is a collection of fields.
(And the type definition matches its literal meaning.)

Copy the codeThe code is as follows:
package main
import "fmt"
type Vertex struct {
    X int
    Y int
}
func main() {
    (Vertex{1, 2})
}

Structure fields are accessed using dot numbers.

Copy the codeThe code is as follows:
package main
import "fmt"
type Vertex struct {
    X int
    Y int
}
func main() {
    v := Vertex{1, 2}
    = 4
    ()
}

I hope this article will be helpful to everyone's Go language programming.