热重载
This commit is contained in:
		
							
								
								
									
										13
									
								
								bin/main.go
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								bin/main.go
									
									
									
									
									
								
							@@ -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) // 最后打印日志
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user