Apache has a vhost. How to implement it purely on Go? Any example?

    1 answer 1

    Like this:

    package main import ( "log" "net/http" ) func indexGo1(rw http.ResponseWriter, req *http.Request) { rw.Write([]byte("hello go1.dev")) } func indexGo2(rw http.ResponseWriter, req *http.Request) { rw.Write([]byte("hello go2.dev")) } func main() { http.HandleFunc("go1.dev/", indexGo1) http.HandleFunc("go2.dev/", indexGo2) if err := http.ListenAndServe(":80", nil); err != nil { log.Fatal(err) } } 

    The go1.dev and go2.dev should be added to /etc/hosts .