-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
73 lines (59 loc) · 1.35 KB
/
main.go
File metadata and controls
73 lines (59 loc) · 1.35 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
package main
import (
"LearnGoLang2/db"
"LearnGoLang2/handler"
"LearnGoLang2/helper"
"LearnGoLang2/log"
"LearnGoLang2/repository/repo_impl"
"LearnGoLang2/router"
"fmt"
"github.com/labstack/echo"
"os"
"time"
)
func init() {
fmt.Println(">>>>", os.Getenv("APP_NAME"))
//os.Setenv("APP_NAME", "github")
log.InitLogger(false)
}
func main() {
sql := &db.Sql{
Host: "host.docker.internal", //,localhost, 192.168.1.163, host.docker.internal
Port: 5433,
UserName: "postgres",
Password: "123456",
DbName: "LearnGolang2",
}
sql.Connect()
defer sql.Close()
e := echo.New()
structValidator := helper.NewStructValidator()
structValidator.RegisterValidate()
e.Validator = structValidator
userHandler := handler.UserHandler{
UserRepo: repo_impl.NewUserRepo(sql),
}
repoHandler := handler.RepoHandler{
GithubRepo: repo_impl.NewGithubRepo(sql),
}
api := router.API{
Echo: e,
Userhandler: userHandler,
RepoHandler: repoHandler,
}
api.SetupRouter()
go scheduleUpdateTrending(360*time.Second, repoHandler)
e.Logger.Fatal(e.Start(":3000"))
}
func scheduleUpdateTrending(timeSchedule time.Duration, handler handler.RepoHandler) {
ticker := time.NewTicker(timeSchedule)
go func() {
for {
select {
case <-ticker.C:
fmt.Println("Checking from github...")
helper.CrawlRepo(handler.GithubRepo)
}
}
}()
}