1 Commits
Author SHA1 Message Date
Hadi e74f69daf7 return an empty list instead of an error if no result
Signed-off-by: Hadi <[email protected]>
2025-09-25 19:15:16 +02:00
3 changed files with 12 additions and 1 deletions
+4 -1
View File
@@ -58,12 +58,15 @@ func main() {
} }
profiles, err := gravatar_recon.GetGravatarProfiles(email) profiles, err := gravatar_recon.GetGravatarProfiles(email)
if err != nil { if err != nil || profiles == nil {
log.Fatal("Failed to get Gravatar profile", "err", err) log.Fatal("Failed to get Gravatar profile", "err", err)
} }
if !*silent { if !*silent {
utils.Header() utils.Header()
if len(*profiles) == 0 {
utils.PrintNoResultFound()
}
for _, profile := range *profiles { for _, profile := range *profiles {
utils.PrintTitle(profile.PreferredUser + ":") utils.PrintTitle(profile.PreferredUser + ":")
if *printAvatar { if *printAvatar {
+4
View File
@@ -91,6 +91,10 @@ func GetGravatarProfiles(email string) (*[]GravatarProfile, error) {
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode == 404 {
return &[]GravatarProfile{}, nil
}
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
return nil, fmt.Errorf("no gravatar profile found (status %d)", resp.StatusCode) return nil, fmt.Errorf("no gravatar profile found (status %d)", resp.StatusCode)
} }
+4
View File
@@ -133,6 +133,10 @@ func PrintTitle(title string) {
fmt.Println(titleStyle.Render(title) + "\n") fmt.Println(titleStyle.Render(title) + "\n")
} }
func PrintNoResultFound() {
fmt.Println(titleStyle.Render("No result found"))
}
func PrintAvatar(url string) { func PrintAvatar(url string) {
if url == "" { if url == "" {
return return