When I run this code in LiteIDE, via the build and run command, it works. But when I run it by
go run scraper.go
Or
go build scraper.go
./scraper
it fails in the r.Body.Close() line with the error
panic: runtime error: invalid memory address or nil pointer dereference
Here's the offending code:
r, err := http.Get(job.Url)
defer r.Body.Close() //same error with or without defer
The script is here: https://gist.github.com/meddulla/5934457 but it basically accepts urls to scrape via post requests, eg
curl -X POST -d "[{\"url\": \"http://localhost:8888/IBTX/proj/dev/article.html\"}]" http://localhost:8080/jobs/add
and I can't understand why it would work in liteIde but not when i run it directly in the terminal (the program starts ok, so its not a GOPATH setting or something, it only fails when responding to post requests)
Any ideias why?