feat: comment cleanup
This commit is contained in:
1 parent
6b14a95434
commit
648c55415b
112 files changed
+655
-2161
No files matched your search
@@ -1,5 +1,4 @@
|
||||
// Package stats - счётчики пропускной способности и обёртка net.Conn
|
||||
// с подсчётом байт. Используется и клиентом, и сервером.
|
||||
// Package stats реализует счётчики сетевого трафика и пропускной способности.
|
||||
package stats
|
||||
|
||||
import (
|
||||
@@ -9,14 +8,13 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Stats хранит счётчики tx/rx байт. При enabled=false Add* - no-op.
|
||||
// Stats хранит счётчики переданных и принятых байт.
|
||||
type Stats struct {
|
||||
tx atomic.Uint64
|
||||
rx atomic.Uint64
|
||||
enabled bool
|
||||
}
|
||||
|
||||
// New возвращает Stats с заданным флагом enabled.
|
||||
func New(enabled bool) *Stats {
|
||||
return &Stats{enabled: enabled}
|
||||
}
|
||||
@@ -25,7 +23,6 @@ func (s *Stats) Counters() (tx, rx uint64) {
|
||||
return s.tx.Load(), s.rx.Load()
|
||||
}
|
||||
|
||||
// AddTx учитывает n переданных байт.
|
||||
func (s *Stats) AddTx(n int) {
|
||||
if n <= 0 {
|
||||
return
|
||||
@@ -36,7 +33,6 @@ func (s *Stats) AddTx(n int) {
|
||||
s.tx.Add(uint64(n))
|
||||
}
|
||||
|
||||
// AddRx учитывает n полученных байт.
|
||||
func (s *Stats) AddRx(n int) {
|
||||
if n <= 0 {
|
||||
return
|
||||
@@ -47,7 +43,7 @@ func (s *Stats) AddRx(n int) {
|
||||
s.rx.Add(uint64(n))
|
||||
}
|
||||
|
||||
// FormatBitsPerSecond форматирует пропускную способность из числа байт и интервала.
|
||||
// FormatBitsPerSecond форматирует пропускную способность (bit/s, kbit/s, Mbit/s).
|
||||
func FormatBitsPerSecond(bytes uint64, interval time.Duration) string {
|
||||
if interval <= 0 {
|
||||
interval = time.Second
|
||||
@@ -63,7 +59,7 @@ func FormatBitsPerSecond(bytes uint64, interval time.Duration) string {
|
||||
return fmt.Sprintf("%.0f bit/s", bps)
|
||||
}
|
||||
|
||||
// FormatByteCount форматирует число байт в человекочитаемый вид.
|
||||
// FormatByteCount форматирует количество байт в человекочитаемый вид (B, KiB, MiB).
|
||||
func FormatByteCount(bytes uint64) string {
|
||||
if bytes >= 1024*1024 {
|
||||
return fmt.Sprintf("%.2f MiB", float64(bytes)/(1024*1024))
|
||||
@@ -74,7 +70,7 @@ func FormatByteCount(bytes uint64) string {
|
||||
return fmt.Sprintf("%d B", bytes)
|
||||
}
|
||||
|
||||
// CountingConn оборачивает net.Conn и аккумулирует rx/tx-счётчики в Stats.
|
||||
// CountingConn оборачивает net.Conn и учитывает прочитанные/записанные байты в Stats.
|
||||
type CountingConn struct {
|
||||
net.Conn
|
||||
Stats *Stats
|
||||
|
||||
Reference in new issue
Block a user