Golang:如何处理和提供子域名?

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.

Given the hosts file in your second edit, you can point firefox to, for example, blog.localhost.com:8080 but then you also have to handle that domain pattern, i.e. http.HandleFunc(blogDomain+":8080/", blogIndex).

If that's not what you want you can instead listen on port 80 i.e. http.ListenAndServe(":80", nil), you might need to run your app in sudo so that it has permission to use that port, then your blog.localhost.com should work.