韓立剛門徒級課程專題(WS+網(wǎng)絡安全+數(shù)據(jù)庫)
2023-08-22 20:44 作者:bili_23282190042 | 我要投稿
新建main.go
文件,該文件為主啟動程序,負責建立HTTP服務以響應客戶端到serveWebsocket
請求響應。
package mainimport (
? ?"flag"
? ?"log"
? ?"net/http")var addr = flag.String("addr", ":3000", "http service address")func serveHome(w http.ResponseWriter, r *http.Request) {
? ?log.Println(r.URL)
? ?if r.URL.Path != "/" {
? ? ? ?http.Error(w, "Not found", http.StatusNotFound)
? ? ? ?return
? ?}
? ?if r.Method != http.MethodGet {
? ? ? ?http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
? ? ? ?return
? ?}
? ?http.ServeFile(w, r, "public/index.html")}
標簽: