Skip to content

Instantly share code, notes, and snippets.

@xvbnm48
Created January 7, 2023 03:16
Show Gist options
  • Save xvbnm48/a660661fff5776c65a6a77570770d346 to your computer and use it in GitHub Desktop.
Save xvbnm48/a660661fff5776c65a6a77570770d346 to your computer and use it in GitHub Desktop.
golang method, struct, and pointer
package main
import (
"fmt"
"strconv"
)
type Person struct {
name string
age int
}
func (p *Person) Birthday() {
p.age++
}
func (p Person) Greet() string {
return "Hello, my name is " + p.name + " and I am " + strconv.Itoa(p.age) + " years old."
}
func main() {
p := Person{"Sakura Miyawaki", 20}
p.Birthday()
fmt.Println(p.Greet())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment