-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (40 loc) · 1.19 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
package main
import (
"net/http"
"time"
)
func main() {
p("ChitChat", version(), "started at", config.Address)
// handle static assets
mux := http.NewServeMux()
files := http.FileServer(http.Dir(config.Static))
mux.Handle("/static/", http.StripPrefix("/static/", files))
//
// all route patterns matched here
// route handler functions defined in other files
//
// index
mux.HandleFunc("/", index)
// error
mux.HandleFunc("/err", err)
// defined in route_auth.go
mux.HandleFunc("/login", login)
mux.HandleFunc("/logout", logout)
mux.HandleFunc("/signup", signup)
mux.HandleFunc("/signup_account", signupAccount)
mux.HandleFunc("/authenticate", authenticate)
// defined in route_thread.go
mux.HandleFunc("/thread/new", newThread)
mux.HandleFunc("/thread/create", createThread)
mux.HandleFunc("/thread/post", postThread)
mux.HandleFunc("/thread/read", readThread)
// starting up the server
server := &http.Server{
Addr: config.Address,
Handler: mux,
ReadTimeout: time.Duration(config.ReadTimeout * int64(time.Second)),
WriteTimeout: time.Duration(config.WriteTimeout * int64(time.Second)),
MaxHeaderBytes: 1 << 20, // 1M
}
server.ListenAndServe()
}