Archived
Compare commits
8
Commits
79f1771d35
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9db57ad178 | ||
|
|
96798db689 | ||
|
|
12b5f9a75f | ||
|
|
366130e9f4 | ||
|
|
dcc58a331a | ||
|
|
3fa2760726 | ||
|
|
16a06ade68 | ||
|
|
82b78bc58c |
@@ -5,6 +5,7 @@
|
|||||||
*.dll
|
*.dll
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
|
main
|
||||||
|
|
||||||
# Test binary, built with `go test -c`
|
# Test binary, built with `go test -c`
|
||||||
*.test
|
*.test
|
||||||
|
|||||||
@@ -4,14 +4,16 @@
|
|||||||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
|
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
|
||||||
<meta http-equiv="Pragma" content="no-cache" />
|
<meta http-equiv="Pragma" content="no-cache" />
|
||||||
<meta http-equiv="Expires" content="0" />
|
<meta http-equiv="Expires" content="0" />
|
||||||
<meta property="og:title" content="{{.Kamoji}}" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta property="og:description" content="{{.Kamoji}}" />
|
<meta property="og:description" content="{{.Kamoji}}" />
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>{{.Kamoji}}</title>
|
<title>{{.Kamoji}}</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<p style="text-align: center; padding: 50px 0; font-size: 5vw">
|
||||||
{{.Kamoji}}
|
{{.Kamoji}}
|
||||||
|
</p>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ func loadKamojis(path string) Kamojis {
|
|||||||
return kamojis
|
return kamojis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func randNum(i int) int {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
return rand.Intn(i)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
port := flag.String("port", "80", "http listening port")
|
port := flag.String("port", "80", "http listening port")
|
||||||
kamojisPath := flag.String("kamojis", "kamojis.txt", "path to file with kamojis")
|
kamojisPath := flag.String("kamojis", "kamojis.txt", "path to file with kamojis")
|
||||||
@@ -53,19 +58,23 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
allk := loadKamojis(*kamojisPath)
|
allk := loadKamojis(*kamojisPath)
|
||||||
|
|
||||||
timestamp := time.Now().Unix()
|
timestamp := time.Now().Unix()
|
||||||
randomNumber := rand.Intn(len(allk.Kamojis))
|
randomNumber := randNum(len(allk.Kamojis))
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if time.Now().Unix()-timestamp > 60 {
|
if time.Now().Unix()-timestamp > 60 {
|
||||||
randomNumber = rand.Intn(len(allk.Kamojis))
|
randomNumber = randNum(len(allk.Kamojis))
|
||||||
timestamp = time.Now().Unix()
|
timestamp = time.Now().Unix()
|
||||||
log.Println("rotating kamoji.")
|
log.Println("rotating kamoji.")
|
||||||
}
|
}
|
||||||
log.Println("served kamoji to " + r.RemoteAddr + ".")
|
log.Println("serving kamoji to " + r.Header.Get("x-forwarded-for") + ".")
|
||||||
k := allk.Kamojis[randomNumber]
|
k := allk.Kamojis[randomNumber]
|
||||||
tmpl.Execute(w, k)
|
tmpl.Execute(w, k)
|
||||||
})
|
})
|
||||||
|
|
||||||
http.ListenAndServe(":"+*port, nil)
|
http.ListenAndServe(":"+*port, nil)
|
||||||
log.Println("starting webserver on port " + *port + ". press ctrl-c to exit.")
|
log.Println("starting webserver on port " + *port + ". press ctrl-c to exit.")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user