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
|
package main
import (
"flag"
"github.com/gorilla/mux"
"github.com/kch42/simplechat/chat"
"log"
"math"
"net/http"
)
var (
laddr = flag.String("laddr", ":8080", "Listen on this address")
tplpath = flag.String("tplpath", "tpls", "Path to templates")
staticpath = flag.String("staticpath", "static", "Path to static page elements")
perroom = flag.Int("perroom", -1, "Maximum amount of users per room (negative for unlimited)")
)
func main() {
flag.Parse()
if *perroom < 0 {
*perroom = math.MaxInt32
} else if *perroom == 0 {
log.Fatalln("flag perroom must not be 0")
}
PrepTemplates()
chat.InitRooms(*perroom)
r := mux.NewRouter()
r.HandleFunc("/", Home)
r.PathPrefix("/static").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(*staticpath))))
r.HandleFunc("/chat/{chatroom}/", Chatpage)
r.HandleFunc("/chat/{chatroom}/socket", AcceptWebSock)
http.Handle("/", r)
http.ListenAndServe(*laddr, nil)
}
|