Documentation ¶
Index ¶
- type Speed
- func (s Speed) BiggerThan(s2 Speed) bool
- func (s Speed) Equals(s2 Speed) bool
- func (s Speed) GetBitSize() float64
- func (s Speed) GetByteSize() float64
- func (s Speed) MarshalJSON() ([]byte, error)
- func (s Speed) SmallerThan(s2 Speed) bool
- func (s Speed) String() string
- func (s *Speed) StringAuto() string
- func (s *Speed) StringWithBitUnit() string
- func (s *Speed) StringWithByteUnit() string
- func (s *Speed) UnmarshalJSON(b []byte) error
- type SpeedCounter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Speed ¶
type Speed float64
bit size of speed 为什么用float64而不用uint64?float64的表示范围比uint64大很多,unint64根本达不到YB级别
const ( Kb Speed = 1 << (10 * iota) // 1 Kb = 1024 bits Mb // 1 Mb = 1048576 bits Gb Tb Pb Eb Zb Yb )
Map between speed unit of bit and bits size
const ( KB Speed = 8 * (1 << (10 * iota)) // 1 KB = (8 * 1024) bits MB // 1 MB = (8 * 1048576) bits GB TB PB EB ZB YB )
Map between speed unit of byte and bits size
func FromBytesInterval ¶
func ParseString ¶
speed string sample: "2M" "2Mb" "2Mbit" "2Mbits" "2Mbyte" "2Mbytes" "2 Mb" "*/s" "*ps"
func (Speed) BiggerThan ¶
func (Speed) GetBitSize ¶
func (Speed) GetByteSize ¶
func (Speed) MarshalJSON ¶
func (Speed) SmallerThan ¶
func (*Speed) StringAuto ¶
func (*Speed) StringWithBitUnit ¶
func (*Speed) StringWithByteUnit ¶
func (*Speed) UnmarshalJSON ¶
type SpeedCounter ¶
type SpeedCounter struct {
// contains filtered or unexported fields
}
func NewCounter ¶
func NewCounter(dur time.Duration) *SpeedCounter
dur: 多长时间之内的数据作为参与统计速度的有效数据。此时长越长,计算得出的速度变化越均匀
func (*SpeedCounter) Add ¶
func (c *SpeedCounter) Add(byteSize uint64)
func (*SpeedCounter) Get ¶
func (c *SpeedCounter) Get() (*Speed, error)
func (*SpeedCounter) Reset ¶
func (c *SpeedCounter) Reset()
Click to show internal directories.
Click to hide internal directories.