Advertisement
marcusziade

Go main refactor songlink

Feb 18th, 2023
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.70 KB | None | 0 0
  1. func main() {
  2.     clipboardContent, err := clipboard.ReadAll()
  3.     if err != nil {
  4.         fmt.Println("An error occurred while reading input. Please try again", err)
  5.         return
  6.     }
  7.     err = getLinks(clipboardContent)
  8.     if err != nil {
  9.         fmt.Println("\n❌", err.Error(), "Check the search URL and retry.")
  10.         return
  11.     }
  12. }
  13.  
  14.  
  15. Refactor for testability, error handling
  16.  
  17. func run() error {
  18.     searchURL, err := clipboard.ReadAll()
  19.     if err != nil {
  20.         return fmt.Errorf("Error reading clipboard: %w", err)
  21.     }
  22.     err = getLinks(searchURL)
  23.     if err != nil {
  24.         return fmt.Errorf("Error getting links: %w", err)
  25.     }
  26.     return nil
  27. }
  28.  
  29. func main() {
  30.     err := run()
  31.     if err != nil {
  32.         fmt.Println("An error occurred:", err)
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement