跳至主要内容

博文

目前显示的是标签为“shutdown”的博文

go server shutdown gracefully

package main import ( "fmt" "html/template" "io" "net/http" "net/url" "os" ) type TData struct { Clipboard, Copy, Send, CbContent, Files string FileSlice                               []string ChooseFile, UploadButton                string } type MyHTTPHandler struct{} var ( mux = make(map[string]func(http.ResponseWriter, *http.Request)) ) func (*MyHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { u, _ := url.Parse(r.RequestURI) if h, ok := mux[u.Path]; ok { h(w, r) return } http.NotFound(w, r) } func main() { mux["/"] = home mux["/send"] = send mux["/downloadFile"] = downloadFile mux["/uploadFile"] = uploadFile myhandler := MyHTTPHandler{} server := http.Server{Addr: ":4444", Handler: &myhandler} err := server.ListenAndServe() if err != nil { fmt.Println(err) } }