go,

Go(lang) and http's empty "unsupported protocol scheme" error

Feb 04, 2023 · 1 min read · Post a comment

A bit controversial opinion, but every DevOps, Cloud engineer needs to know at least how to read application code. As I started my app development journey with Go, also known as Golang, I’ve faced a dozen of issues. To start with, here’s a solution to a general Go’s http package issue: Get "google.com": unsupported protocol scheme "" while trying to send a GET request method to google.com.

Prerequisites

  • Go(lang)
  • Go http package

Solution

Take the following basic HTTP GET code snippet as an example:

package main
import (
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
)

func main() {
	resp, err := http.Get("google.com")
	if err != nil {
		log.Fatal(err)
	}

	defer resp.Body.Close()

    body, err := ioutil.ReadAll(resp.Body)

    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(string(body))
}

If you run this code, without doubt, you’ll get the unsupported protocol scheme "" error.

As for the solution goes, you need to add http:// or https:// in front of google.com. Happy coding!

Conclusion

If you have any other great solutions on this topic, or even issues, feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.