I have a small server and I want that server to listen to my custom domain sftablet.dev using gorilla/mux package.
Here is the code:
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.Host("sftablet.dev")
r.HandleFunc("/", HomeHandler)
r.HandleFunc("/products", ProductsHandler)
http.ListenAndServe(":8080", r)
}
func HomeHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hey, this is homepage")
}
func ProductsHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hey, this is products")
}
I also added this in the hosts file:
127.0.0.1 sftablet.dev
But for some reason it doesn't work. It does work if I go to 127.0.0.1:8080, but not when I access http://sftablet.dev/. Also cleared the DNS cache.