filepath.Walk() returned 0xc08402f180

Issue

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.

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)
}

Answered By – Nick Craig-Wood

Answer Checked By – Candace Johnson (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.