DEV Community

vasubabu
vasubabu

Posted on

Solution: UnSupported Protocol scheme golang issue

Recently I had faced an issue while using net/http to get the resource from an URL:

Here is my program:

package main import ( "fmt" "log" "net/http" ) type WebScrapper interface { PullContent(url string) } type webScrapper struct { } func (w *webScrapper) PullContent(url string) { resp, err := http.Get(url) if err != nil { panic(err) } defer (func() { if r := recover(); r != nil { fmt.Printf("Recovered from panic %s", r) } })() log.Printf("Got response for %s and status is %s", url, resp.Status) } func main() { w := webScrapper{} urls := []string{ "www.google.com", "www.facebook.com", "www.gmail.com", } for i := 0; i < len(urls); i++ { w.PullContent(urls[i]) } } 

yes its a lot of code, but don't worry about code having interfaces and structs and defer. The code is breaking mainly at getting resource from URL.

Error:

 Get www.google.com: unsupported protocol scheme "" 

Solution:

To fix unsupported protocol scheme prepend http:// before every URL.

urls := []string{ "http://www.google.com", "http://www.facebook.com", "http://www.gmail.com", } 

That's it!!!

Top comments (0)