热重载

This commit is contained in:
2024-10-25 00:57:50 +08:00
parent 342d25811d
commit d3e3a0d79b
7 changed files with 161 additions and 525 deletions

View File

@@ -60,6 +60,13 @@ func LogComponent(startTime int64, r *http.Request) {
log.Println(method, url, endTime, r.Header.Get("X-Forwarded-For"))
}
func LogRequest(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
next.ServeHTTP(w, r)
})
}
type Image struct {
Id int `json:"id" db:"id"`
Width int `json:"width" db:"width"`
@@ -186,7 +193,7 @@ func (image *Image) GetSimilarImagesIdList(collection_name string) (ids []int64)
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
runtime.GOMAXPROCS(runtime.NumCPU() - 1)
viper.SetConfigFile("./data/config.yaml")
if err := viper.ReadInConfig(); err != nil {
@@ -224,11 +231,11 @@ func main() {
w.Write([]byte("Hello World!"))
})
http.Handle("/api", handler.New(&handler.Config{
http.Handle("/api", LogRequest(handler.New(&handler.Config{
Schema: &schema,
Playground: true,
Pretty: false,
}))
})))
//http.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
// defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志