v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/time2/timeutil/httptime.go (about) 1 package timeutil 2 3 import ( 4 "net/http" 5 "strconv" 6 "time" 7 ) 8 9 func TimeHandler(w http.ResponseWriter, _ *http.Request) { 10 t1 := float64(time.Now().UnixNano()) / 1e6 // ms 11 w.Header().Set("Content-Type", "application/json") 12 w.WriteHeader(http.StatusOK) 13 //{"t1":1668210427454.1458,"t2":1668210427454.1487} 14 var buffer []byte = make([]byte, 0, 50) 15 buffer = append(buffer, "{\"t1\":"...) 16 buffer = strconv.AppendFloat(buffer, t1, 'f', 4, 64) 17 buffer = append(buffer, ",\"t2\":"...) 18 t2 := float64(time.Now().UnixNano()) / 1e6 // ms 19 buffer = strconv.AppendFloat(buffer, t2, 'f', 4, 64) 20 buffer = append(buffer, "}"...) 21 w.Write(buffer) 22 }