-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (47 loc) · 1.26 KB
/
main.go
File metadata and controls
58 lines (47 loc) · 1.26 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
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"log"
"net/http"
"time"
"github-proxy/config"
"github-proxy/handler"
"github-proxy/static"
)
func init() {
// 设置日志格式
log.SetFlags(log.LstdFlags | log.Lshortfile)
}
func main() {
// 加载配置
cfg := config.GetConfig()
// 创建代理处理器
proxyHandler := handler.NewProxyHandler(cfg)
// 创建路由
mux := http.NewServeMux()
// 注册路由
// 在main.go的路由注册部分
//mux.HandleFunc("/favicon.ico", handler.FaviconHandler)
// 添加对静态资源的处理
mux.Handle("/static/", http.StripPrefix("/static/", static.FileServer))
// 首页和代理处理保持不变
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/" {
handler.IndexHandler(w, r)
} else {
proxyHandler.ServeHTTP(w, r)
}
})
// 创建服务器
server := &http.Server{
Addr: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port),
Handler: mux,
ReadTimeout: 30 * time.Second,
WriteTimeout: 60 * time.Second,
IdleTimeout: 120 * time.Second,
}
// 启动服务器
log.Printf("[INFO] 启动GitHub代理服务器,监听地址: %s:%d", cfg.Host, cfg.Port)
log.Printf("[INFO] 配置: JsDelivr=%v, 调试=%v", cfg.JsDelivr, cfg.Debug)
log.Fatal(server.ListenAndServe())
}