Question

I am new to the Go language and trying to learn.

I made a program to walk through a directory. It worked fine but when I try to run the program in a go routine it returns:

filepath.Walk() returned 0xc08402f180

my function is this:

func LoadData(root string) {
    runtime.GOMAXPROCS(runtime.NumCPU())
    c := make(chan error)
    go func() {c<-filepath.Walk(root, WalkFunc)}()
    if erw := c; erw != nil {
        fmt.Printf("filepath.Walk() returned %v\n", erw)
    // log.Fatal(erw)
    }
}

How can I solve this problem?

Thanks.

Was it helpful?

Solution

You are printing the channel, not the return from the channel. Try this

if erw := <-c; erw != nil {
    fmt.Printf("filepath.Walk() returned %v\n", erw)
//  log.Fatal(erw)
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top