forked from byebyehair/minichat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (31 loc) · 905 Bytes
/
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
package main
import (
"embed"
"fmt"
"log"
"minichat/config"
"minichat/conversation"
"minichat/server"
"net/http"
)
//go:embed static
var DirStatic embed.FS
//go:embed templates/*
var DirTemplate embed.FS
func main() {
http.HandleFunc("/precheck", server.PreCheck)
http.HandleFunc("/ws", server.HandleWs)
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
server.HandleFiles(writer, request, DirTemplate)
})
fs := http.FileServer(http.FS(DirStatic))
http.Handle("/static/", fs)
go conversation.Manager.Start()
configVal := config.ParseConfig("config.yaml")
log.Printf("\n\n********************************\nChat server is running at %d !\n********************************\n\n", configVal.Port)
err := http.ListenAndServe(fmt.Sprintf(":%d", configVal.Port), nil)
if err != nil {
fmt.Printf("Server start fail, error is: [ %+v ]", err)
return
}
}