https://github.com/thatmattlove/go-asn
Autonomous System Number Utility for Go
https://github.com/thatmattlove/go-asn
asn bgp network-automation networking routing-protocols
Last synced: 3 months ago
JSON representation
Autonomous System Number Utility for Go
- Host: GitHub
- URL: https://github.com/thatmattlove/go-asn
- Owner: thatmattlove
- License: bsd-3-clause-clear
- Created: 2023-08-05T04:31:58.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-06T18:54:15.000Z (about 2 years ago)
- Last Synced: 2025-04-09T21:44:15.271Z (6 months ago)
- Topics: asn, bgp, network-automation, networking, routing-protocols
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Installation
```console
go get github.com/thatmattlove/go-asn
```## Usage
### Parsing
```go
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
```go
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
```go
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
```go
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
// 65505a := asn.MustParse("65000")
for iter := a.Iter(); iter.Continue(); {
next := iter.Next()
fmt.Println(next.ASPlain())
}
// 65001
// 65002
// ...
// 4294967294
```