Created
March 19, 2023 19:12
-
-
Save d1str0/160d3cc7cabf4e58159e8167e7afe9fd to your computer and use it in GitHub Desktop.
This file contains 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 ( | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
) | |
func main() { | |
// Define command-line flags | |
urlFlag := flag.String("url", "", "the URL to make an HTTP request to") | |
// Parse flags | |
flag.Parse() | |
// Check if URL flag is set | |
if *urlFlag == "" { | |
fmt.Println("Please specify a URL using the -url flag") | |
return | |
} | |
// Make HTTP request | |
resp, err := http.Get(*urlFlag) | |
if err != nil { | |
fmt.Printf("Error making HTTP request: %s\n", err.Error()) | |
return | |
} | |
defer resp.Body.Close() | |
// Read response body | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
fmt.Printf("Error reading response body: %s\n", err.Error()) | |
return | |
} | |
// Print response body | |
fmt.Println(string(body)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment