-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
executable file
·42 lines (36 loc) · 843 Bytes
/
Copy pathmain.go
File metadata and controls
executable file
·42 lines (36 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"flag"
"fmt"
"log"
"net/http"
)
var addr = flag.String("addr", ":30747", "http service address")
func serveHome(w http.ResponseWriter, r *http.Request) {
fmt.Println(r.URL)
fmt.Printf("Received request from %v for Path: [%s]\n", r.RemoteAddr, r.URL.Path)
if r.URL.Path != "/" {
fmt.Printf("[%s] not found\n", r.URL.Path)
http.Error(w, "Not found", 404)
return
}
if r.Method != "GET" {
http.Error(w, "Method not allowed", 405)
return
}
http.ServeFile(w, r, "resource/html/index.html")
}
func main() {
flag.Parse()
hub := newHub()
go hub.run()
http.HandleFunc("/", serveHome)
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
clientWs(hub, w, r)
})
log.Println(*addr)
err := http.ListenAndServe(*addr, nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}