Why not try our most basic debug tool: printf.
package main
import "fmt"
type myStruct struct {
songs []string
}
func main() {
s1 := myStruct{songs:[]string{"Master of Puppets", "Battery"}}
foo(s1)
}
func foo(s myStruct) {
// Does something with s
for i:=0;i<len(s.songs);i++ {
fmt.Printf("s.songs[%d]=\"%s\"
",i, s.songs[i])
}
}
output:
s.songs[0]="Master of Puppets"
s.songs[1]="Battery"
In case you really want to test if your structure was properly initialized inside your main function:
package main
import "fmt"
type myStruct struct {
songs []string
}
func main() {
s1 := myStruct{songs:[]string{"Master of Puppets", "Battery"}}
foo(s1)
for i:=0;i<len(s1.songs);i++ {
fmt.Printf("s1.songs[%d]=\"%s\"
",i, s1.songs[i])
}
}
func foo(s myStruct) {
// Does something with s
fmt.Printf("foo has finished its work!
")
}
output:
foo has finished its work!
s1.songs[0]="Master of Puppets"
s1.songs[1]="Battery"
If you want to make sure both main() and foo() are working with the same object, try this:
package main
import "fmt"
type myStruct struct {
songs []string
}
func main() {
s1 := myStruct{songs:[]string{"Master of Puppets", "Battery"}}
foo(&s1)
fmt.Printf("main() says: s1 lives in the address:%p
",&s1)
}
func foo(s *myStruct) {
// Does something with s
fmt.Printf("foo() says: s lives in the address:%p
",s)
}
output:
foo() says: s lives in the address:0x10434120
main() says: s1 lives in the address:0x10434120
Next time, try being more specific on your questions.
Cheers.