Declaration of a struct type
A struct type rectangle is declared that has three data fields of different data-types. Here, struct used without instantiate a new instance of that type.
Example
package main
import "fmt"
type rectangle struct {
length float64
breadth float64
color string
}
func main() {
fmt.Println(rectangle{10.5, 25.10, "red"})
}
The rectangle struct and its fields are not exported to other packages because identifiers are started with an lowercase letter. In Golang, identifiers are exported to other packages if the name starts with an uppercase letter, otherwise the accessibility will be limited within the package only.
Most Helpful This Week
Web Application to generate QR code in Golang
How do you handle HTTP server HTTP/2 in Go?
Example to compare Println vs Printf
GO language program with example of Array Reverse Sort Functions for integer and strings
Comparing Structs with the Different Values Assigned to Data Fields
How do you set headers in an HTTP request with an HTTP client in Go?