mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-01-04 08:15:21 -05:00
Add Port as a type
This commit is contained in:
23
common/net/port.go
Normal file
23
common/net/port.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Port uint16
|
||||
|
||||
func NewPort(port int) Port {
|
||||
return Port(uint16(port))
|
||||
}
|
||||
|
||||
func (this Port) Value() uint16 {
|
||||
return uint16(this)
|
||||
}
|
||||
|
||||
func (this Port) Bytes() []byte {
|
||||
return []byte{byte(this >> 8), byte(this)}
|
||||
}
|
||||
|
||||
func (this Port) String() string {
|
||||
return strconv.Itoa(int(this))
|
||||
}
|
||||
Reference in New Issue
Block a user