I was trying to make a simple webapp in Go/Golang. My main fuction code is :
func main() {
fileServer := http.FileServer(http.Dir("./static"))
http.Handle("/", fileServer)
http.HandleFunc("/form", formHandler)
http.HandleFunc("/hello", helloHandler)
fmt.Printf("Starting server at port 8080\n")
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
}
When I run the go run main.go
I get the following error:
listen tcp: address ;8080: missing port in address
exit status 1
I tried using the lsof -i :8080
command but got no output. Chaging the port to :80
from :8080
had no effect. nc -l :8080
didn't work too.
How do I resolve this issue?
PS: I'm using Fedora OS
I know this is old but incase of anyone else who may have this issue. Try specifying the port as "localhost:8080" instead of just ":8080"
In this case, the code should be like this:
func main() {
fileServer := http.FileServer(http.Dir("./static"))
http.Handle("/", fileServer)
http.HandleFunc("/form", formHandler)
http.HandleFunc("/hello", helloHandler)
fmt.Printf("Starting server at port 8080\n")
if err := http.ListenAndServe("localhost:8080", nil); err != nil {
log.Fatal(err)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With