Method related
method is a special function with the reciever parameter.
https://tour/golang.org Package Main
Import ("FMT" "math")
Type Vertex struct{
X, Y float64
}
There's no class concept in Go
method, a function with the parameters of the recipient
Func (v Vertex) AbsMethod1 () float64 {
return Math. SQRT (v.x*v.x + v.y*v.y)
}
function ordinary Functions,
Func AbsFunc1 (v Vertex) float64{
return Math. SQRT (v.x*v.x + v.y*v.y)}
Zoom method, with receiver
Func (v *vertex) Scalemethod (f float64) {
v.x = v.x * F v.y = v.y * F}
Zoom, function, and pointers, where the pointer is more like a reference
Func Scalefunc (v *vertex, f float64) {
v.x *= F v.y *= F}
Func Main () {
V: = vertex{3, 4}
Fmt. Println ("=====method abs=", V.absmethod ())
Fmt. Println ("=====function Abs =", AbsFunc1 (v))
V.scalemethod (Ten) fmt. Println ("vvvv===", V)
Fmt. Println (V.absmethod ()) Scalefunc (&v, 2)
Fmt. Println (v)
P: = &v p.absmethod1 ()//Here P.absmethod1 () is interpreted as (*p). ABSMETHOD1 ()
}
Go Basics: Method Related