- 
      
- 
        Save 0xlitf/dbeb3f34b9516e3e72c5f37d71141e05 to your computer and use it in GitHub Desktop. 
    Example of using http.Get in go (golang)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package main | |
| import ( | |
| "fmt" | |
| "io" | |
| "log" | |
| "net/http" | |
| "os" | |
| ) | |
| func main() { | |
| if len(os.Args) != 2 { | |
| fmt.Fprintf(os.Stderr, "Usage: %s URL\n", os.Args[0]) | |
| os.Exit(1) | |
| } | |
| response, err := http.Get(os.Args[1]) | |
| if err != nil { | |
| log.Fatal(err) | |
| } else { | |
| defer response.Body.Close() | |
| _, err := io.Copy(os.Stdout, response.Body) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment