1
0
Fork 0
mirror of https://github.com/actions/go-versions synced 2024-11-26 21:02:39 +00:00
go-versions/tests/source/methods/methods.go
2020-06-09 22:52:06 +03:00

26 lines
No EOL
412 B
Go

package main
import "fmt"
type rect struct {
width, height int
}
func (r *rect) area() int {
return r.width * r.height
}
func (r rect) perim() int {
return 2*r.width + 2*r.height
}
func main() {
r := rect{width: 10, height: 5}
fmt.Println("area: ", r.area())
fmt.Println("perim:", r.perim())
rp := &r
fmt.Println("area: ", rp.area())
fmt.Println("perim:", rp.perim())
}