Solution: UnSupported Protocol scheme golang issue

jinagam vasubabu
1 min readDec 5, 2019

--

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 resources from URL.

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!!!

Originally published at https://dev.to on December 5, 2019.

--

--

jinagam vasubabu

A typical software engineer who travels daily 4 hours to office in bangalore traffic :) #hangoutdude hangoutdude.com