-
Notifications
You must be signed in to change notification settings - Fork 21
/
main.go
58 lines (47 loc) · 1.04 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
// "html/template"
"log"
"net/http"
// "os"
// "strings"
)
func init() {
Config()
MustConnectRedis()
}
func main() {
http.HandleFunc("/", index)
http.HandleFunc("/drop", drop)
log.Println("Start listening...")
err := http.ListenAndServe(":80", nil)
if err != nil {
panic(err)
}
}
func index(res http.ResponseWriter, req *http.Request) {
defer func() {
if e := recover(); e != nil {
log.Println(e)
res.WriteHeader(http.StatusInternalServerError)
}
}()
log.Println("Index home")
err := IncNum()
if err != nil {
log.Println(err)
}
request, err := GetNum()
if err != nil {
res.WriteHeader(http.StatusInternalServerError)
log.Println(err)
return
}
res.Write([]byte(fmt.Sprintf("Request number is %d", request)))
}
func drop(res http.ResponseWriter, req *http.Request) {
log.Println("drop collection")
Drop()
http.Redirect(res, req, "/", 302)
}