Skip to content

Instantly share code, notes, and snippets.

@drio
Created January 20, 2023 17:26
Show Gist options
  • Save drio/3e840ce98cfdc414a616f5b0047dcef9 to your computer and use it in GitHub Desktop.
Save drio/3e840ce98cfdc414a616f5b0047dcef9 to your computer and use it in GitHub Desktop.
package main
import (
"embed"
"html/template"
"io/ioutil"
"log"
"net/http"
"os"
)
//go:embed templates/*
var resources embed.FS
var t = template.Must(template.ParseFS(resources, "templates/*"))
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
uri := "http://localhost:8181/"
resp, err := http.Get(uri)
if err != nil {
log.Fatalf("http.Get() failed with '%s'\n", err)
}
defer resp.Body.Close()
d, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalf("ioutil.ReadAll() failed with '%s'\n", err)
}
data := map[string]string{
"Region": os.Getenv("FLY_REGION"),
"LocalData": string(d),
}
t.ExecuteTemplate(w, "index.html.tmpl", data)
})
log.Println("listening on", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment