-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (56 loc) · 1.43 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"context"
"errors"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/awcjack/cloudbet/application"
"github.com/awcjack/cloudbet/infrastructure"
"github.com/awcjack/cloudbet/interfaces"
"github.com/sirupsen/logrus"
)
func main() {
repo := infrastructure.NewMemoryRepository()
logger := logrus.New()
logger.SetLevel(logrus.DebugLevel)
app := application.NewApplication(repo, repo, repo, repo, logger)
httpServer := interfaces.NewHttpServer(*app)
server := &http.Server{
Addr: ":8080",
Handler: interfaces.NewHandler(*httpServer),
}
go func() {
if err := server.ListenAndServe(); err != nil && errors.Is(err, http.ErrServerClosed) {
log.Printf("listen: %s\n", err)
}
}()
cloudbetCrawler := application.NewCloudbetHander(repo, logger, "<YOUR_API_KEY>")
ticker := time.NewTicker(5 * time.Second)
exitTicker := make(chan struct{})
go func() {
for {
select {
case <-ticker.C:
cloudbetCrawler.StoreAllEvents(context.Background())
cloudbetCrawler.CheckEventsCloseToCutOff(context.Background())
// do stuff
case <-exitTicker:
ticker.Stop()
return
}
}
}()
quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
close(exitTicker)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
log.Fatal("Server forced to shutdown:", err)
}
}