This builds well.why doesn't this code execute?

Issue

I am trying to make a web scraper using go. I built this code. It was built fine without any errors. But its binary won’t execute.

Is this the problem with a large number of routines or those variables in the execute function?

package main

import (
    "io/ioutil"
    "net/http"
    //"regexp"
)

func excuter(count int) {

    adrr := string("http://torhit.com/torbite/?page=" + string(count))

    resp, _ := http.Get(adrr)
    bytes, _ := ioutil.ReadAll(resp.Body)

    ioutil.WriteFile("scrap.txt"+string(count), bytes, 0777)

    resp.Body.Close()
}
func main() {
    //re := regexp.MustCompile("")
    count := 1
    maxcount := 200
    for ; count <= maxcount; count++ {
        go excuter(count)

    }
}

    package main

import (
    "io/ioutil"
    "net/http"
    //"regexp"
)

func excuter(count int) {

    adrr := string("http://torhit.com/torbite/?page=" + string(count))

    resp, _ := http.Get(adrr)
    bytes, _ := ioutil.ReadAll(resp.Body)

    ioutil.WriteFile("scrap.txt"+string(count), bytes, 0777)

    resp.Body.Close()
}
func main() {
    //re := regexp.MustCompile("")
    count := 1
    maxcount := 200
    for ; count <= maxcount; count++ {
        go excuter(count)

    }
}

Solution

Maybe your error is come from this :

string(count)

It will compiled but the result is empty. If you want to convert int to string you will need strconv package.

strconv.Itoa(count)

Or

strconv.FormatInt(int64(count), 10)

Answered By – Apin

Answer Checked By – Clifford M. (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.