add first working version with example template and kamojis
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
|
||||
<meta http-equiv="Pragma" content="no-cache" />
|
||||
<meta http-equiv="Expires" content="0" />
|
||||
<meta property="og:title" content="{{.Kamoji}}" />
|
||||
<meta property="og:description" content="{{.Kamoji}}" />
|
||||
<meta charset="UTF-8">
|
||||
<title>{{.Kamoji}}</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{{.Kamoji}}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
¯\_(ツ)_/¯
|
||||
(=^ ◡ ^=)
|
||||
(⊃。•́‿•̀。)⊃━☆*:・゚
|
||||
♬♫♪◖(● o ●)◗♪♫♬
|
||||
( ╯°□°)╯ ┻━━┻
|
||||
┬─┬ノ( º _ ºノ)
|
||||
(-‸ლ)
|
||||
(*¯︶¯*)
|
||||
凸( ` ロ ´ )凸
|
||||
(+_+)
|
||||
ლ(ಠ_ಠ ლ)
|
||||
( ̄▽ ̄)ノ
|
||||
(づ ◕‿◕ )づ
|
||||
C= C= C= C=┌( `ー´)┘
|
||||
( ̄o ̄) zzZZzzZZ
|
||||
@@ -0,0 +1,58 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"html/template"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Kamoji struct {
|
||||
Kamoji string
|
||||
}
|
||||
|
||||
type Kamojis struct {
|
||||
Kamojis []Kamoji
|
||||
}
|
||||
|
||||
func loadKamojis() Kamojis {
|
||||
kamojis := Kamojis{}
|
||||
|
||||
file, err := os.Open("kamojis.txt")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
kamojis.Kamojis = append(kamojis.Kamojis, Kamoji{Kamoji: scanner.Text()})
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return kamojis
|
||||
}
|
||||
|
||||
func main() {
|
||||
tmpl, err := template.ParseFiles("kamoji_template.html")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
allk := loadKamojis()
|
||||
timestamp := time.Now().Unix()
|
||||
randomNumber := rand.Intn(len(allk.Kamojis))
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
if time.Now().Unix()-timestamp > 60 {
|
||||
randomNumber = rand.Intn(len(allk.Kamojis))
|
||||
timestamp = time.Now().Unix()
|
||||
}
|
||||
k := allk.Kamojis[randomNumber]
|
||||
tmpl.Execute(w, k)
|
||||
})
|
||||
http.ListenAndServe(":80", nil)
|
||||
}
|
||||
Reference in New Issue
Block a user