generated from Yandex-Practicum/go_final_project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
44 lines (34 loc) · 912 Bytes
/
main.go
File metadata and controls
44 lines (34 loc) · 912 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
42
43
44
package main
import (
"fmt"
"log"
"os"
"github.com/AlexFox86/scheduler/internal/api"
"github.com/AlexFox86/scheduler/internal/repository/sqlite"
"github.com/AlexFox86/scheduler/internal/server"
"github.com/AlexFox86/scheduler/internal/service/auth"
"github.com/AlexFox86/scheduler/internal/service/tasks"
_ "modernc.org/sqlite"
)
func main() {
dbFile := os.Getenv("TODO_DBFILE")
if dbFile == "" {
fmt.Println("Env variable TODO_DBFILE not found")
dbFile = "scheduler.db"
}
// Init repository
repo := sqlite.NewSQLiteRepo()
err := repo.Init(dbFile)
defer repo.Close()
if err != nil {
panic(err)
}
// Create a new scheduler service
taskService := tasks.New(repo)
// Create a new auth service
authService := auth.New(os.Getenv("SECRET"))
// Init handlers and api module
handler := api.NewHandler(taskService, authService)
// Start server
log.Fatal(server.Start(handler))
}