title: Golang: How to handle and serve subdomains?
body: <p>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.</p>
  
  <pre><code>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)
      }
  }
  </code></pre>
  
  <p>Is it possible to serve subdomains using the standard library? If so how?</p>
  
  <p><strong>EDIT:</strong> Requesting localhost:8080/ works fine</p>
  
  <p><strong>EDIT2:</strong> I edited /etc/hosts to include the subdomains:</p>
  
  <pre><code>127.0.0.1 blog.localhost.com
  127.0.0.1 admin.localhost.com
  127.0.0.1 design.localhost.com
  </code></pre>
  
  <p>Pinging them works correctly but firefox cannot reach them.</p>