package main
import (
"log"
"net/http"
"os"
"os/signal"
)
type webhandler struct {
}
type web2handler struct {
}
func (webhandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("web1"))
}
func (web2handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("web2"))
}
func main() {
c := make(chan os.Signal) //监听信号
go func() {
http.ListenAndServe(":9091", webhandler{})
}()
go func() {
http.ListenAndServe(":9092", web2handler{})
}()
signal.Notify(c, os.Interrupt) //监听到ctrlc的时候写入c chan,取消阻塞
s := <-c
log.Println(s)
}