1 Star 0 Fork 0

junqirao / links-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
type.go 583 Bytes
一键复制 编辑 原始数据 按行查看 历史
junqirao 提交于 2022-11-12 21:03 . feat: 添加cidr地址支持
package ipaddr
import (
"encoding/binary"
"fmt"
"net"
"strings"
)
type ipAddress []byte
func (i *ipAddress) uint32() uint32 {
if i == nil {
return 0
}
return binary.BigEndian.Uint32(*i)
}
func (i *ipAddress) CIDR(mask int) string {
return fmt.Sprintf("%s/%v", i.String(), mask)
}
func (i *ipAddress) String() string {
if i == nil {
return ""
}
var out []string
for _, n := range *i {
out = append(out, fmt.Sprintf("%d", n))
}
return strings.Join(out, ".")
}
func (i *ipAddress) IP() net.IP {
if i == nil {
return nil
}
return net.ParseIP(i.String())
}
Go
1
https://gitee.com/jackrabbit872568318/links-core.git
git@gitee.com:jackrabbit872568318/links-core.git
jackrabbit872568318
links-core
links-core
v0.1.3

搜索帮助