27 lines
616 B
Go
27 lines
616 B
Go
// flow 包示例:流量统计(只统计、不限制),常配合 conn 包做连接流量上报
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.zeroonesoft.cn/golib/zogo/flow"
|
|
)
|
|
|
|
func main() {
|
|
f := &flow.Flow{}
|
|
|
|
// 模拟收发流量(单位:字节)
|
|
f.Add(1024, 2048)
|
|
f.Add(512, 1024)
|
|
|
|
send, recv := f.Get()
|
|
fmt.Printf("已发送: %d 字节, 已接收: %d 字节\n", send, recv)
|
|
|
|
// 汇总并清零(常用于周期性上报)
|
|
send, recv = f.Reset()
|
|
fmt.Printf("Reset 返回 - 发送: %d, 接收: %d\n", send, recv)
|
|
|
|
send, recv = f.Get()
|
|
fmt.Printf("清零后 - 发送: %d, 接收: %d\n", send, recv)
|
|
}
|