Custom Data Type Declaration and Receiver function with Example in Go:
Custom Data Type in Golang:
----------------------------
int float string ....
custom data type
i.e.
type deck []string
cards := deck{"A", "B", "C"}
Receiver function in Golang:
----------------------------
With the use of Golang receiver functions, you don’t have to mess around with classes or deal with inheritance. Go is very similar to C due to the presence of pointers, static typing, and many other things.
But Go is the modern language and so it has many new features baked in it, and Function Receiver is one of it.
Function Receiver sets a method on variables that we create. This seems weird at first, but when you get the example, it will be clear as crystal.
//receiver’s function
func (d deck) printW() {
for i, card := range d {
fmt.Println(i, card)
}
}
Function in go
func printW() {
for i, card := range d {
fmt.Println(i, card)
}
}