Skip to content

Instantly share code, notes, and snippets.

@d1str0
Created March 19, 2023 19:12
Show Gist options
  • Save d1str0/160d3cc7cabf4e58159e8167e7afe9fd to your computer and use it in GitHub Desktop.
Save d1str0/160d3cc7cabf4e58159e8167e7afe9fd to your computer and use it in GitHub Desktop.
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