Created
April 5, 2018 12:54
-
-
Save afreeland/03d7d956985c931e9644df72fbff7f3f to your computer and use it in GitHub Desktop.
Go: struct methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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