Created
January 29, 2022 19:21
-
-
Save Th0masStorm/8e2601da7f48619e79a1c03a2e566d2a to your computer and use it in GitHub Desktop.
Dummy AZ printer
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 ( | |
"bufio" | |
"fmt" | |
"net/http" | |
) | |
func handler(w http.ResponseWriter, req *http.Request) { | |
// Request AWS metadata for Availability zone | |
az_endpoint := "http://169.254.169.254/latest/meta-data/placement/availability-zone" | |
resp, err := http.Get(az_endpoint) | |
if err != nil { | |
fmt.Fprintf(w, "I could not reach meta-data endpoint!") | |
} else { | |
defer resp.Body.Close() | |
scanner := bufio.NewScanner(resp.Body) | |
for i := 0; scanner.Scan(); i++ { | |
fmt.Fprintf(w, scanner.Text()) | |
} | |
} | |
} | |
func main() { | |
http.HandleFunc("/", handler) | |
http.ListenAndServe(":8080", nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment