-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
47 lines (40 loc) · 1.15 KB
/
main.go
File metadata and controls
47 lines (40 loc) · 1.15 KB
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
package main
import (
"fmt"
"net/http"
"github.com/TChi91/ChitChat/data"
)
func main() {
mux := http.NewServeMux()
files := http.FileServer(http.Dir("/public"))
mux.Handle("/static/", http.StripPrefix("/static/", files))
mux.HandleFunc("/", index)
// mux.HandleFunc("/err", err)
// mux.HandleFunc("/login", login)
// mux.HandleFunc("/logout", logout)
// mux.HandleFunc("/signup", signup)
// mux.HandleFunc("/signup_account", signupAccount)
// mux.HandleFunc("/authenticate", authenticate)
// mux.HandleFunc("/thread/new", newThread)
// mux.HandleFunc("/thread/create", createThread)
// mux.HandleFunc("/thread/post", postThread)
// mux.HandleFunc("/thread/read", readThread)
server := &http.Server{
Addr: "0.0.0.0:8080",
Handler: mux,
}
server.ListenAndServe()
}
func index(writer http.ResponseWriter, request *http.Request) {
threads, err := data.Threads()
if err != nil {
fmt.Fprint(writer, "Cannot get threads")
} else {
_, err := session(writer, request)
if err != nil {
generateHTML(writer, threads, "layout", "public.navbar", "index")
} else {
generateHTML(writer, threads, "layout", "private.navbar", "index")
}
}
}