更新文档
This commit is contained in:
57
web/web.go
Normal file
57
web/web.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user