forked from nonfu/chitchat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
31 lines (24 loc) · 823 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
package main
import (
. "github.com/xueyuanjun/chitchat/config"
. "github.com/xueyuanjun/chitchat/routes"
"log"
"net/http"
)
func main() {
startWebServer()
}
// 通过指定端口启动 Web 服务器
func startWebServer() {
r := NewRouter() // 通过 router.go 中定义的路由器来分发请求
// 处理静态资源文件
assets := http.FileServer(http.Dir(ViperConfig.App.Static))
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", assets))
http.Handle("/", r)
log.Println("Starting HTTP service at " + ViperConfig.App.Address)
err := http.ListenAndServe(ViperConfig.App.Address, nil)
if err != nil {
log.Println("An error occured starting HTTP listener at " + ViperConfig.App.Address)
log.Println("Error: " + err.Error())
}
}