Skip to content

Commit

Permalink
Support IPs with no ASN
Browse files Browse the repository at this point in the history
Resolves #10
  • Loading branch information
ammario committed Oct 8, 2018
1 parent 0c58123 commit 65229eb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions asn.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ type ASN int

// ParseASN parses a string like `AS2341` into ASN `2341`.
func ParseASN(asn string) (ASN, error) {
// A special value from the API.
// More info: https://github.com/ammario/ipisp/issues/10.
if asn == "NA" {
return 0, nil
}
// Make case insensitive
asn = strings.ToUpper(asn)
if len(asn) > 2 && asn[:2] == "AS" {
Expand All @@ -23,7 +28,11 @@ func ParseASN(asn string) (ASN, error) {
return ASN(nn), errors.Wrap(err, "failed to conv into to string")
}


// String represents an ASN like `5544`` as `AS5544`.`
func (a ASN) String() string {
if a == 0 {
return "N/A"
}
return "AS" + strconv.Itoa(int(a))
}

0 comments on commit 65229eb

Please sign in to comment.