The problem is serving the domain as well as subdomains x,y,z (or in this example blog, admin, and design). When running the following and requesting blog.localhost:8080/ firefox cant find the server www.blog.localhost:8080.
package main
import (
"html/template"
"log"
"net/http"
)
var tpl *template.Template
const (
domain = "localhost"
blogDomain = "blog." + domain
adminDomain = "admin." + domain
designDomain = "design." + domain
)
func init() {
tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
}
func main() {
// Default Handlers
http.HandleFunc("/", index)
// Blog Handlers
http.HandleFunc(blogDomain+"/", blogIndex)
// Admin Handlers
http.HandleFunc(adminDomain+"/", adminIndex)
// Design Handlers
http.HandleFunc(designDomain+"/", designIndex)
http.Handle("/static/", http.StripPrefix("/static", http.FileServer(http.Dir("static"))))
http.ListenAndServe(":8080", nil)
}
func index(res http.ResponseWriter, req *http.Request) {
err := tpl.ExecuteTemplate(res, "index.gohtml", nil)
if err != nil {
log.Fatalln("template didn't execute: ", err)
}
}
// Blog Handlers
func blogIndex(res http.ResponseWriter, req *http.Request) {
err := tpl.ExecuteTemplate(res, "index.gohtml", nil)
if err != nil {
log.Fatalln("template didn't execute: ", err)
}
}
// Admin Handlers
func adminIndex(res http.ResponseWriter, req *http.Request) {
err := tpl.ExecuteTemplate(res, "index.gohtml", nil)
if err != nil {
log.Fatalln("template didn't execute: ", err)
}
}
// Design Handlers
func designIndex(res http.ResponseWriter, req *http.Request) {
err := tpl.ExecuteTemplate(res, "index.gohtml", nil)
if err != nil {
log.Fatalln("template didn't execute: ", err)
}
}
Is it possible to serve subdomains using the standard library? If so how?
EDIT: Requesting localhost:8080/ works fine
EDIT2: I edited /etc/hosts to include the subdomains:
127.0.0.1 blog.localhost.com
127.0.0.1 admin.localhost.com
127.0.0.1 design.localhost.com
Pinging them works correctly but firefox cannot reach them.