Created
November 14, 2016 15:06
-
-
Save shapeshed/89b087805e9035a6c5ea67c53361238c 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 ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"net/http/httputil" | |
"os" | |
) | |
func main() { | |
debug := os.Getenv("DEBUG") | |
client := &http.Client{} | |
request, err := http.NewRequest("GET", "https://ifconfig.co", nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
if debug == "1" { | |
debugRequest, err := httputil.DumpRequestOut(request, true) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("%s", debugRequest) | |
} | |
response, err := client.Do(request) | |
defer response.Body.Close() | |
if debug == "1" { | |
debugResponse, err := httputil.DumpResponse(response, true) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("%s", debugResponse) | |
} | |
body, err := ioutil.ReadAll(response.Body) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("%s", body) | |
} |
Author
shapeshed
commented
Nov 14, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment