更新文档

This commit is contained in:
2026-02-26 16:10:17 +08:00
parent 54c2903c75
commit 539477de4b
5 changed files with 94 additions and 113 deletions

57
web/web.go Normal file
View File

@@ -0,0 +1,57 @@
package web
import (
"context"
"log/slog"
"net/http"
"os"
"os/signal"
)
func Start() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)
defer cancel()
// 初始化数据库和 Redis
// model.Init()
// defer model.Close()
// clients.InitRedis()
// defer clients.CloseRedis()
// 测试
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, World!"))
})
// 同步节点
http.HandleFunc("/sync", func(w http.ResponseWriter, r *http.Request) {
})
// 更新节点
http.HandleFunc("/update", func(w http.ResponseWriter, r *http.Request) {
})
// 标记上线
http.HandleFunc("/up", func(w http.ResponseWriter, r *http.Request) {
})
// 标记下线
http.HandleFunc("/down", func(w http.ResponseWriter, r *http.Request) {
})
// 启动服务
server := http.Server{Addr: ":8080"}
go func() {
<-ctx.Done()
server.Shutdown(ctx)
}()
if err := server.ListenAndServe(); err != nil {
slog.Error("启动服务失败", "error", err)
}
}