-
Notifications
You must be signed in to change notification settings - Fork 1
/
httpserver.go
42 lines (34 loc) · 985 Bytes
/
httpserver.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
33
34
35
36
37
38
39
40
41
42
package main
import (
"strconv"
"time"
"net/http"
"github.com/TheSp1der/goerror"
)
func webRoot(resp http.ResponseWriter, req *http.Request, sData <-chan iex) {
resp.Header().Add("Cache-Control", "no-cache, no-store, must-revalidate")
resp.Header().Add("Expires", "0")
resp.Header().Add("Content-Type", "text/html")
if req.Method == "GET" {
resp.Write([]byte(displayWeb(<-sData)))
}
}
func webListener(s <-chan iex, port int) {
ws := http.NewServeMux()
srv := &http.Server{
Addr: ":" + strconv.Itoa(port),
Handler: ws,
// time to read request headers
ReadTimeout: time.Duration(15 * time.Second),
// time from accept to end of response
WriteTimeout: time.Duration(10 * time.Second),
// time a Keep-Alive connection will be kept idle
IdleTimeout: time.Duration(120 * time.Second),
}
ws.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
webRoot(w, r, s)
})
if err := srv.ListenAndServe(); err != nil {
goerror.Fatal(err)
}
}