mirror of
https://github.com/woodchen-ink/proxy-go.git
synced 2025-07-18 16:41:54 +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 请求日志
|
// RequestLog 请求日志
|
||||||
type RequestLog struct {
|
type RequestLog struct {
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"Time"`
|
||||||
Path string `json:"path"`
|
Path string `json:"Path"`
|
||||||
Status int `json:"status"`
|
Status int `json:"Status"`
|
||||||
Latency int64 `json:"latency"`
|
Latency int64 `json:"Latency"`
|
||||||
BytesSent int64 `json:"bytes_sent"`
|
BytesSent int64 `json:"BytesSent"`
|
||||||
ClientIP string `json:"client_ip"`
|
ClientIP string `json:"ClientIP"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathMetrics 路径指标
|
// PathMetrics 路径指标
|
||||||
|
@ -279,7 +279,7 @@ export default function DashboardPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatBytes(bytes: number) {
|
function formatBytes(bytes: number) {
|
||||||
if (bytes === 0) return "0 B"
|
if (!bytes || isNaN(bytes)) return "0 B"
|
||||||
const k = 1024
|
const k = 1024
|
||||||
const sizes = ["B", "KB", "MB", "GB"]
|
const sizes = ["B", "KB", "MB", "GB"]
|
||||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||||
@ -287,11 +287,13 @@ function formatBytes(bytes: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatDate(dateStr: string) {
|
function formatDate(dateStr: string) {
|
||||||
|
if (!dateStr) return "-"
|
||||||
const date = new Date(dateStr)
|
const date = new Date(dateStr)
|
||||||
return date.toLocaleTimeString()
|
return date.toLocaleString()
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatLatency(nanoseconds: number) {
|
function formatLatency(nanoseconds: number) {
|
||||||
|
if (!nanoseconds || isNaN(nanoseconds)) return "-"
|
||||||
if (nanoseconds < 1000) {
|
if (nanoseconds < 1000) {
|
||||||
return nanoseconds + " ns"
|
return nanoseconds + " ns"
|
||||||
} else if (nanoseconds < 1000000) {
|
} else if (nanoseconds < 1000000) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user