-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
58 lines (46 loc) · 1.23 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
package main
import (
"flag"
"log"
"os"
"time"
"github.com/dinopuguh/mycap-backend/database"
_ "github.com/dinopuguh/mycap-backend/docs"
"github.com/dinopuguh/mycap-backend/migrations"
"github.com/dinopuguh/mycap-backend/routes"
"github.com/dinopuguh/mycap-backend/scheduler"
"github.com/dinopuguh/mycap-backend/seed"
"github.com/go-co-op/gocron"
)
// @title MyCap API
// @version 1.0
// @description This is an API for MyCap Application
// @contact.name Dino Puguh
// @contact.email dinopuguh@gmail.com
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @BasePath /api
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name Authorization
func main() {
if err := database.Connect(); err != nil {
panic("Can't connect database.")
}
migrate := flag.Bool("migrate", false, "Migrate all models to database")
flag.Parse()
if *migrate {
migrations.All()
}
for _, seeder := range seed.AllTypes() {
if err := seeder.Run(database.DBConn); err != nil {
log.Fatalln(err.Error())
}
}
cron := gocron.NewScheduler(time.UTC)
cron.Every(1).Month(8).Do(scheduler.ResetTimeLimit)
cron.StartAsync()
port := os.Getenv("PORT")
app := routes.New()
log.Fatal(app.Listen(":" + port))
}