mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-18 08:31:55 +08:00
refactor(models,web): Update JSON serialization and formatting utilities
- Modify RequestLog struct to use PascalCase JSON tags - Enhance formatBytes function to handle undefined or NaN inputs - Update formatDate to return full datetime and handle empty inputs - Add null/NaN checks to formatLatency for more robust display
This commit is contained in:
parent
b5a6928a3a
commit
eabb1f1f9a
@ -7,12 +7,12 @@ import (
|
||||
|
||||
// RequestLog 请求日志
|
||||
type RequestLog struct {
|
||||
Time time.Time `json:"time"`
|
||||
Path string `json:"path"`
|
||||
Status int `json:"status"`
|
||||
Latency int64 `json:"latency"`
|
||||
BytesSent int64 `json:"bytes_sent"`
|
||||
ClientIP string `json:"client_ip"`
|
||||
Time time.Time `json:"Time"`
|
||||
Path string `json:"Path"`
|
||||
Status int `json:"Status"`
|
||||
Latency int64 `json:"Latency"`
|
||||
BytesSent int64 `json:"BytesSent"`
|
||||
ClientIP string `json:"ClientIP"`
|
||||
}
|
||||
|
||||
// PathMetrics 路径指标
|
||||
|
@ -279,7 +279,7 @@ export default function DashboardPage() {
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number) {
|
||||
if (bytes === 0) return "0 B"
|
||||
if (!bytes || isNaN(bytes)) return "0 B"
|
||||
const k = 1024
|
||||
const sizes = ["B", "KB", "MB", "GB"]
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
@ -287,11 +287,13 @@ function formatBytes(bytes: number) {
|
||||
}
|
||||
|
||||
function formatDate(dateStr: string) {
|
||||
if (!dateStr) return "-"
|
||||
const date = new Date(dateStr)
|
||||
return date.toLocaleTimeString()
|
||||
return date.toLocaleString()
|
||||
}
|
||||
|
||||
function formatLatency(nanoseconds: number) {
|
||||
if (!nanoseconds || isNaN(nanoseconds)) return "-"
|
||||
if (nanoseconds < 1000) {
|
||||
return nanoseconds + " ns"
|
||||
} else if (nanoseconds < 1000000) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user