Skip to content

Instantly share code, notes, and snippets.

@afreeland
Created April 5, 2018 12:54
Show Gist options
  • Save afreeland/03d7d956985c931e9644df72fbff7f3f to your computer and use it in GitHub Desktop.
Save afreeland/03d7d956985c931e9644df72fbff7f3f to your computer and use it in GitHub Desktop.
Go: struct methods
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, playground")
mp := messagePrint{"foo"}
mp.printMessage()
}
type messagePrint struct {
message string
}
// (mp *messagePrint) => this signature before function name indicates it will be a method for the reference struct
func (mp *messagePrint) printMessage() {
println(mp.message)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment