Created
March 23, 2022 14:30
-
-
Save mweitzel/52560567a92ea18079a2b52d999707d9 to your computer and use it in GitHub Desktop.
golang thing thang
This file contains 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" | |
) | |
type thing struct { | |
str string | |
} | |
func (thinger thing) BadSet(str string) { | |
thinger.str = str | |
} | |
func (thinger *thing) GoodSet(str string) { | |
thinger.str = str | |
} | |
func main() { | |
thinger := thing{} | |
thinger.BadSet("one") | |
fmt.Println(thinger) | |
thinger.GoodSet("two") | |
fmt.Println(thinger) | |
thinger2 := thinger | |
thinger.GoodSet("three") | |
fmt.Println(thinger2) | |
fmt.Println("--------------") | |
thanger := &thing{} | |
thanger.BadSet("one") | |
fmt.Println(thanger) | |
thanger.GoodSet("two") | |
fmt.Println(thanger) | |
thanger2 := thanger | |
thanger.GoodSet("three") | |
fmt.Println(thanger2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A snippet I shared with a handful of folks who are learning go.