Unable to listen with WSL2

Viewed 247

I've copy and pasted the "hello world" example from here

package main

import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/", HelloServer)
    http.ListenAndServe(":8000", nil)
}

func HelloServer(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
}

And tried to run it on Ubuntu 20.04, installed on WSL2.

However, when I try to browse to 'http://127.0.0.1:8000', the server is not reachable.

To verify that this is not a port blocking issue, I ran python -m http.server

And the web page loaded correctly.

What might be the issue?

===UPDATE====

For some reason, browsing to

http://localhost:8000

Does work, an mentioned in this thread

0 Answers
Related