-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
41 lines (29 loc) · 959 Bytes
/
main.go
File metadata and controls
41 lines (29 loc) · 959 Bytes
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
package main
import (
"fmt"
"log"
"net/http"
"time"
"github.com/LockBlock-dev/javascriptdle/controller"
"github.com/LockBlock-dev/javascriptdle/repository"
"github.com/LockBlock-dev/javascriptdle/utils"
)
const HTTP_PORT = 8080
func main() {
log.Println("--- JavaScriptDle ---")
guessableRepo := repository.NewMemoryGuessableRepository()
guessController := controller.NewGuessController(guessableRepo)
go func() {
ticker := time.NewTicker(24 * time.Hour)
defer ticker.Stop()
utils.GenerateTodaysGuess(guessableRepo)
for range ticker.C {
utils.GenerateTodaysGuess(guessableRepo)
}
}()
http.HandleFunc("GET /", guessController.Home)
http.HandleFunc("POST /guess", guessController.Guess)
http.Handle("GET /public/", http.StripPrefix("/public/", http.FileServer(http.Dir("public"))))
log.Printf("Started listening on http://localhost:%d\n", HTTP_PORT)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", HTTP_PORT), nil))
}