mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2024-12-30 02:37:01 +00:00
fix duration()
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"sort"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/message"
|
||||
@@ -60,21 +59,12 @@ func (s *simpleSessionStater) Start() error {
|
||||
return sessions[i].SessionStart.After(sessions[j].SessionStart)
|
||||
})
|
||||
|
||||
// Duration from session uptime
|
||||
duration := func(sess stats.Session) time.Duration {
|
||||
if sess.SessionClose.IsZero() {
|
||||
return time.Now().Sub(sess.SessionStart).Round(time.Millisecond)
|
||||
} else {
|
||||
return sess.SessionClose.Sub(sess.SessionStart).Round(time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
for _, sess := range sessions {
|
||||
_, _ = fmt.Fprintf(w, "<tr><td>%v</td><td>%v</td><td>%v</td><td>%v</td><td>%v</td><td>%v</td><td>%v</td><td>%v</td><td>%v</td></tr>",
|
||||
sess.ProcessName,
|
||||
sess.Network,
|
||||
date(sess.SessionStart),
|
||||
duration(sess),
|
||||
duration(sess.SessionStart, sess.SessionClose),
|
||||
sess.DialerAddr,
|
||||
sess.ClientAddr,
|
||||
sess.TargetAddr,
|
||||
|
||||
@@ -20,6 +20,14 @@ func now() string {
|
||||
return time.Now().Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
func duration(start, end time.Time) time.Duration {
|
||||
if end.IsZero() {
|
||||
return time.Now().Sub(start).Round(time.Millisecond)
|
||||
} else {
|
||||
return end.Sub(start).Round(time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
func uptime() string {
|
||||
// Y M d h m s
|
||||
now := time.Now()
|
||||
|
||||
Reference in New Issue
Block a user