This repository was archived by the owner on Jun 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
76 lines (65 loc) · 1.29 KB
/
Copy pathmain.go
File metadata and controls
76 lines (65 loc) · 1.29 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"html/template"
"log"
"net/http"
"os"
)
// hi hi hi hi mike!
var html = template.Must(template.New("html").Parse(`
<!DOCTYPE html>
<html>
<head>
<meta name="mobile-web-app-capable" content="yes">
<link rel="icon" sizes="192x192" href="favicon.ico">
<meta name="viewport" content="initial-scale=1, user-scalable=no">
<title>Butt Generator</title>
<script>
{{.JS}}
</script>
<style>
.butt {
position: fixed;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%;
max-width: 100%;
max-height: 100%;
}
</style>
</head>
<body>
{{.Image}}
</body>
</html>
`))
func handler(w http.ResponseWriter, r *http.Request) {
image := Butt(r.URL.Path == "/spot")
js := svg_js
if r.URL.Path == "/original" {
image = `<img class="butt" src="images/butt.jpg" alt="A smiling butt.">`
js = ""
}
err := html.Execute(w, struct {
Image template.HTML
JS template.JS
}{
Image: template.HTML(image),
JS: template.JS(js),
})
if err != nil {
log.Println("error executing template: ", err)
}
}
func main() {
http.HandleFunc("/", handler)
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Printf("listening on port %s", port)
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Fatal(err)
}
}