Answer the question
In order to leave comments, you need to log in
How to setup subroute in gorilla mux golang?
Let's say I have a site example.com and a subdomain sub.example.com
I want to handle example.com/ and sub.example.com/ with different handlers
I do it like this
router := mux.NewRouter()
r1 := router.Host("example.com/").Subrouter()
r1.HandleFunc("/", hand1)
r2 := router.Host("sub.example.com").Subrouter()
r2.HandleFunc("/", hand2)
http.ListenAndServe(":8080", router)
Answer the question
In order to leave comments, you need to log in
You need to remove '/' from example.com/, i.e. should be router.Host("example.com").Subrouter()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question