-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
47 lines (34 loc) · 851 Bytes
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"context"
"embed"
"html/template"
"log"
"net/http"
"os"
"github.com/fly-apps/go-example-tigris/tigris"
)
//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) {
data := map[string]string{
"Region": os.Getenv("FLY_REGION"),
}
t.ExecuteTemplate(w, "index.html.tmpl", data)
})
http.HandleFunc("/sample-upload-tigris", func(w http.ResponseWriter, r *http.Request) {
res,_ := tigris.UploadText(context.TODO())
data := map[string]string{
"Region": res,
}
t.ExecuteTemplate(w, "index.html.tmpl", data)
})
log.Println("listening on", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}