-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
32 lines (27 loc) · 636 Bytes
/
main.go
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
package main
import (
"log"
"net/http"
"strconv"
)
func main () {
mux := http.NewServeMux()
mux.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request){
query := request.URL.Query()
page, err := strconv.Atoi(query.Get("page")) ; if err != nil {
writer.WriteHeader(500)
log.Print(err)
}
log.Print("page", page)
writer.WriteHeader(200)
_, err = writer.Write([]byte("ok")) ; if err != nil {
writer.WriteHeader(500)
log.Print(err)
}
})
log.Print("http://127.0.0.1:3000/")
err := http.ListenAndServe(":3000", mux) ; if err != nil {
// 服务无法启动必须 panic
panic(err)
}
}