mirror of
https://github.com/woodchen-ink/random-api-go.git
synced 2025-07-18 05:42:01 +08:00
fix(handlers, public): update timestamp logging to use Unix milliseconds
- Changed timestamp logging in the HandleAPIRequest function to use Unix milliseconds for improved precision. - Updated the recent requests display in the HTML to correctly parse and format timestamps using the new millisecond format, enhancing readability and consistency in metrics presentation.
This commit is contained in:
parent
0a41bebf39
commit
f92b8385d8
@ -55,7 +55,7 @@ func (h *Handlers) HandleAPIRequest(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if len(pathSegments) < 2 {
|
||||
monitoring.LogRequest(monitoring.RequestLog{
|
||||
Time: time.Now().Unix(),
|
||||
Time: time.Now().UnixMilli(),
|
||||
Path: r.URL.Path,
|
||||
Method: r.Method,
|
||||
StatusCode: http.StatusNotFound,
|
||||
@ -76,7 +76,7 @@ func (h *Handlers) HandleAPIRequest(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if !ok {
|
||||
monitoring.LogRequest(monitoring.RequestLog{
|
||||
Time: time.Now().Unix(),
|
||||
Time: time.Now().UnixMilli(),
|
||||
Path: r.URL.Path,
|
||||
Method: r.Method,
|
||||
StatusCode: http.StatusNotFound,
|
||||
@ -92,7 +92,7 @@ func (h *Handlers) HandleAPIRequest(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
log.Printf("Error fetching CSV content: %v", err)
|
||||
monitoring.LogRequest(monitoring.RequestLog{
|
||||
Time: time.Now().Unix(),
|
||||
Time: time.Now().UnixMilli(),
|
||||
Path: r.URL.Path,
|
||||
Method: r.Method,
|
||||
StatusCode: http.StatusInternalServerError,
|
||||
@ -106,7 +106,7 @@ func (h *Handlers) HandleAPIRequest(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if len(selector.URLs) == 0 {
|
||||
monitoring.LogRequest(monitoring.RequestLog{
|
||||
Time: time.Now().Unix(),
|
||||
Time: time.Now().UnixMilli(),
|
||||
Path: r.URL.Path,
|
||||
Method: r.Method,
|
||||
StatusCode: http.StatusNotFound,
|
||||
@ -124,7 +124,7 @@ func (h *Handlers) HandleAPIRequest(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
duration := time.Since(start)
|
||||
monitoring.LogRequest(monitoring.RequestLog{
|
||||
Time: time.Now().Unix(),
|
||||
Time: time.Now().UnixMilli(),
|
||||
Path: r.URL.Path,
|
||||
Method: r.Method,
|
||||
StatusCode: http.StatusFound,
|
||||
|
@ -232,7 +232,7 @@
|
||||
// 最近请求
|
||||
const recentRequestsHtml = metrics.recent_requests.map(req => `
|
||||
<tr>
|
||||
<td>${new Date(req.time * 1000).toLocaleString()}</td>
|
||||
<td>${new Date(req.time).toLocaleString()}</td>
|
||||
<td>${req.path}</td>
|
||||
<td>${req.method}</td>
|
||||
<td>${req.status_code}</td>
|
||||
|
Loading…
x
Reference in New Issue
Block a user