golang网络篇一

简单说说反向代理

golang网络篇一

 golang网络篇一

 信号监听方式启动两个web服务,分别是9091 9092 分别返回 web1 web2

type web1handler struct {}
func(web1handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
    writer.Write([]byte("web1"))
}
type web2handler struct {}
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",web1handler{})
    })()

    go(func() {
        http.ListenAndServe(":9092",web2handler{})
    })()
    signal.Notify(c,os.Interrupt)
    s:=<-c
    log.Println(s)
}