Skip to content

Instantly share code, notes, and snippets.

@Th0masStorm
Created January 29, 2022 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Th0masStorm/8e2601da7f48619e79a1c03a2e566d2a to your computer and use it in GitHub Desktop.
Save Th0masStorm/8e2601da7f48619e79a1c03a2e566d2a to your computer and use it in GitHub Desktop.
Dummy AZ printer
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