DEV Community

vasubabu
vasubabu

Posted on

3 2

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs