|
Kmoving |
at Jan 23, 2015 at 1:29 pm
|
⇧ |
| |
I have the similar needs and google brings me here, after some dig on the
net/http/server.go code,
i think the better way to do this maybe like this:
package main
import (
"fmt"
"net/http"
)
func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "hello")
}
func world(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "world")
}
func main() {
serverMuxA := http.NewServeMux()
serverMuxA.HandleFunc("/hello", hello)
serverMuxB := http.NewServeMux()
serverMuxB.HandleFunc("/world", world)
go func() {
http.ListenAndServe("localhost:8081", serverMuxA)
}()
http.ListenAndServe("localhost:8082", serverMuxB)
}
hope this will be helpful to you:)
在 2013年6月11日星期二 UTC+8上午8:34:58,Kyle Wolfe写道:
I want to be able to run two separate http servers concurrently on
different port numbers. http.ListenAndServe already puts the script into a
never ending state, but if I start two separate go routines, the script
will immediately exit. I've also tried only calling one as a go routine but
I get an error of 'multiple registrations'
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.