Created
November 26, 2020 18:58
-
-
Save madflojo/f57b749a00cd50a6d28350847055fdc8 to your computer and use it in GitHub Desktop.
maps.vs.struct.typeassert
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
// Print out one of our JSON values | |
n, ok := data["name"] | |
if !ok { | |
// access it another way | |
n = "default" | |
} | |
v, ok := n.(string) | |
if !ok { | |
// figure out type another way | |
v = "default" | |
} | |
fmt.Printf("Name is %s", v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment