跳至主要内容

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)
}
}

评论

此博客中的热门博文

android hide actionbar

public class MainActivity extends Activity { ActionBar actionBar; //声明ActionBar @Override protected void onCreate( Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView( R .layout.activity_main); actionBar = getSupportActionBar(); //得 到ActionBar actionBar.hide(); //隐藏ActionBar } }

go url encoding

func  QueryUnescape func QueryUnescape (s string ) ( string , error ) QueryUnescape does the inverse transformation of QueryEscape, converting %AB into the byte 0xAB and '+' into ' ' (space). It returns an error if any % is not followed by two hexadecimal digits. func  QueryUnescape func QueryUnescape (s string ) ( string , error ) QueryUnescape does the inverse transformation of QueryEscape, converting %AB into the byte 0xAB and '+' into ' ' (space). It returns an error if any % is not followed by two hexadecimal digits.