Created
March 27, 2022 07:04
-
-
Save vincentiusronalto/73bdc6c831af6d42f4878f9fa99b2a3e to your computer and use it in GitHub Desktop.
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" | |
"github.com/davecgh/go-spew/spew" | |
) | |
type Base1 struct { | |
X *int | |
Y *int | |
Z Base2 | |
} | |
type Base2 struct { | |
A *int | |
B Base3 | |
} | |
type Base3 struct { | |
C []Base4 | |
} | |
type Base4 struct { | |
D *int | |
} | |
func main() { | |
a := 10 | |
b := 20 | |
c := 30 | |
d := Base4{&a} | |
e := Base3{[]Base4{d, d}} | |
nestedStruct := Base1{&a, &b, Base2{&c, e}} | |
normalInt := 100 | |
var negativeVal32 int32 = -100 | |
var negativeVal64 int64 = -1e9 | |
var floatVal32 float32 = 230.2 | |
var floatVal64 float64 = 20011.23 | |
mapExample := map[string]interface{}{ | |
"name": "John", | |
"country": "USA", | |
} | |
//manual | |
fmt.Println(nestedStruct) | |
fmt.Println(*nestedStruct.X) | |
fmt.Println(*nestedStruct.Y) | |
fmt.Println(*nestedStruct.Z.A) | |
fmt.Println(*nestedStruct.Z.B.C[0].D) | |
fmt.Println("") | |
//go-spew | |
spew.Dump(nestedStruct) // or spew.Dump(&nestedStruct) | |
spew.Dump(normalInt) | |
spew.Dump(negativeVal32) | |
spew.Dump(negativeVal64) | |
spew.Dump(floatVal32) | |
spew.Dump(floatVal64) | |
spew.Dump(mapExample) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment