fix pointers

This commit is contained in:
2022-01-07 21:47:18 +00:00
parent 9c58c2af2e
commit b6670cc921
2 changed files with 14 additions and 9 deletions

View File

@@ -14,7 +14,7 @@ func main() {
utils.ParseFlags(&ip, &properties, &detail) utils.ParseFlags(&ip, &properties, &detail)
// Use the IP-API to lookup the IP address // Use the IP-API to lookup the IP address
data := ipapi.Lookup(&ip, &properties) data := ipapi.Lookup(ip, properties)
// Format the data to a string // Format the data to a string
result := ipapi.GetProperties(data, properties, detail) result := ipapi.GetProperties(data, properties, detail)

View File

@@ -36,6 +36,11 @@ type IPAPI struct {
Message string `json:"message"` Message string `json:"message"`
} }
// Add the .String() method to IPAPI
func (i *IPAPI) String() string {
return i.Query
}
// Build URL to query IP-API // Build URL to query IP-API
// https://ip-api.com/docs/api:json // https://ip-api.com/docs/api:json
func buildURL(ip string) string { func buildURL(ip string) string {
@@ -45,24 +50,24 @@ func buildURL(ip string) string {
// Get IP-API data about IP // Get IP-API data about IP
// //
// https://ip-api.com/docs/api:json // https://ip-api.com/docs/api:json
func Lookup(ip *string, properties *string) *IPAPI { func Lookup(ip string, properties string) *IPAPI {
var data *IPAPI var data *IPAPI
if *ip == "" { if ip == "" {
if *properties == "" { if properties == "" {
*properties = "Query" properties = "Query"
} }
} else { } else {
if *properties == "" { if properties == "" {
*properties = "Country" properties = "Country"
} }
if !utils.CheckValidIP(*ip) { if !utils.CheckValidIP(ip) {
utils.PrintOut("Invalid IP address during Lookup") utils.PrintOut("Invalid IP address during Lookup")
utils.Exit(1) utils.Exit(1)
} }
} }
url := buildURL(*ip) url := buildURL(ip)
resp, err := http.Get(url) resp, err := http.Get(url)
utils.HandleError(err) utils.HandleError(err)