Skip to content

thatmattlove/go-asn

Repository files navigation

go-asn


Autonomous System Number Utility for Go

GitHub Workflow Status Codecov GitHub tag (with filter) GoDoc Reference

Installation

go get github.com/thatmattlove/go-asn

Usage

Parsing

a, err := asn.Parse("65000")
a, err := asn.FromDecimal("65000")
a, err := asn.FromASDot("64086.59904")
a, err := asn.FromUint64(65001)
a, err := asn.FromBytes(255, 255, 253, 232)
a := asn.From4Bytes(255, 255, 253, 232)
a := asn.From2Bytes(253, 232)
a := asn.FromUint32(65001)
a := asn.MustParse("65000")
a := asn.MustDecimal("65000")
a := asn.MustASDot("0.65000")

Formatting

a := asn.MustParse("65000")
a.Size()
// 2
a.ASPlain()
// 65000
a.ASDot()
// 65000
a.ASDotPlus()
// 0.65000
a.String()
// 65000
a.ByteString()
// {0,0,253,232}

a = asn.MustParse("4200000000")
a.Size()
// 4
a.ASPlain()
// 4200000000
a.ASDot()
// 64086.59904
a.ASDotPlus()
// 64086.59904
a.String()
// 4200000000
a.ByteString()
// {250,86,234,0}

Comparison

a := asn.MustParse("65000")
b := asn.MustParse("65001")
c := asn.MustParse("65002")
d := asn.MustParse("65000")
e := asn.MustParse("64512")
a.Equal(b)
// false
a.Equal(d)
// true
a.LessThan(b)
// true
a.LEqual(c)
// true
a.GreaterThan(e)
// true
a.GEqual(e)
// true

Iteration

start := asn.MustParse("65000")
end := asn.MustParse("65005")

for iter := start.Range(end); iter.Continue(); {
    next := iter.Next()
    fmt.Println(next.ASPlain())
}
// 65001
// 65002
// 65003
// 65004
// 65505

a := asn.MustParse("65000")
for iter := a.Iter(); iter.Continue(); {
    next := iter.Next()
    fmt.Println(next.ASPlain())
}
// 65001
// 65002
// ...
// 4294967294

GitHub