@@ -42,6 +42,14 @@ func (err *InvalidASNError) Error() string {
4242 return "invalid ASN: " + err .ASN
4343}
4444
45+ // Set `v.CountryName` properly by mapping country abbreviation to full country
46+ // name.
47+ func (v * ASNDetails ) setCountryName () {
48+ if v .Country != "" {
49+ v .CountryName = countriesMap [v .Country ]
50+ }
51+ }
52+
4553// GetASNDetails returns the details for the specified ASN.
4654func GetASNDetails (asn string ) (* ASNDetails , error ) {
4755 return DefaultClient .GetASNDetails (asn )
@@ -53,35 +61,31 @@ func (c *Client) GetASNDetails(asn string) (*ASNDetails, error) {
5361 return nil , & InvalidASNError {ASN : asn }
5462 }
5563
56- cacheKey := "asn:" + asn
57-
5864 // perform cache lookup.
5965 if c .Cache != nil {
60- if res , err := c .Cache .Get (cacheKey ); err == nil {
66+ if res , err := c .Cache .Get (asn ); err == nil {
6167 return res .(* ASNDetails ), nil
6268 }
6369 }
6470
6571 // prepare req
66- req , err := c .NewRequest ( asn + "/json" )
72+ req , err := c .newRequest ( nil , "GET" , asn , nil )
6773 if err != nil {
6874 return nil , err
6975 }
7076
7177 // do req
7278 v := new (ASNDetails )
73- if _ , err := c .Do (req , v ); err != nil {
79+ if _ , err := c .do (req , v ); err != nil {
7480 return nil , err
7581 }
7682
77- // map country to full country name
78- if v .Country != "" {
79- v .CountryName = countriesMap [v .Country ]
80- }
83+ // format
84+ v .setCountryName ()
8185
8286 // cache req result
8387 if c .Cache != nil {
84- if err := c .Cache .Set (cacheKey , v ); err != nil {
88+ if err := c .Cache .Set (asn , v ); err != nil {
8589 return v , err
8690 }
8791 }
0 commit comments