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
How do you set headers in an HTTP response in Go?
How do you read headers from an HTTP response with an HTTP client in Go?
Cannot convert <type1> to <type2> error in Golang
Program in Go language to print Pascal's Triangle
How to convert Boolean Type to String in Go?
Example to use various String Functions in Go Language