-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
134 lines (100 loc) · 4.77 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main
import (
"fmt"
"fog/common"
"fog/db"
"fog/db/genericmodels"
"fog/db/repository"
"fog/services"
"fog/tasks"
"fog/tasks/definitions"
"fog/tasks/workers"
"fog/web"
"fog/web/routes"
"fog/work"
"net/http"
)
func main() {
logger := common.NewStdFileLogger()
logger.Info("Starting Application")
props, err := common.LoadProperties("dev")
if err != nil {
logger.Fatal("Could not load props.")
return
}
conn := db.NewDbConn(props["sqliteDbLocation"], logger)
if conn == nil {
logger.Fatal("Could not establish connection to database, Exiting...")
return
}
conn.Up()
// directories := repository.NewDirectorySet(conn, logger)
// directories.Add(models.Directory{Id: fmt.Sprintf("0x%x", [16]byte(uuid.New())), Path: "/usr/test/"})
// files := repository.NewFileSet(conn, logger)
// dirList, err := directories.List(100, 0)
// if err != nil {
// logger.Error(err)
// }
// someDir := dirList[0]
// someFile := models.File{Id: fmt.Sprintf("0x%x", [16]byte(uuid.New())), Path: "a.exe", ParentDirectory: someDir.Id}
// files.Add(someFile)
// fileList, err := files.List(100, 0)
// for _, file := range fileList {
// logger.Infof("%#v", file)
// }
tplEngine := routes.NewTplEngine(logger)
tplEngine.RegisterTemplate("./web/static/templates/main.template.html", "main")
tplEngine.RegisterTemplate("./web/static/templates/body.template.html", "body")
tplEngine.RegisterTemplate("./web/static/templates/header.template.html", "header")
tplEngine.RegisterTemplate("./web/static/templates/navigation.template.html", "navigation")
router := web.NewTplRouter(logger, tplEngine)
indexRoute := routes.NewIndexRoute(logger, tplEngine)
orchestartor := tasks.NewOrchestrator("amqp://guest:guest@localhost:5672/", logger)
// fileRepository := repository.NewFileRepository(logger, conn)
fileRepository := repository.NewRepository(logger, conn.GetDB(), &genericmodels.File{})
fileService := services.NewFileService(logger, fileRepository, orchestartor)
// directoryRepository := repository.NewDirectorySet(conn, logger)
directoryRepository := repository.NewRepository(logger, conn.GetDB(), &genericmodels.Directory{})
directoryService := services.NewDirectoryService(logger, directoryRepository, fileService, orchestartor)
// tagRepository := repository.NewTagRepository(logger, conn)
// tagService := services.NewTagService(logger, tagRepository)
exifFn := workers.GetExifFn()
exifResponder := definitions.GetExifWorkHandler()
exifWorkers := tasks.NewWorkerGroup("exif", exifResponder, orchestartor.GetConnection(), logger)
go exifWorkers.Start()
orchestartor.RegisterGroup(exifWorkers)
worker := tasks.NewWorker(orchestartor.GetConnection(), "exif", exifFn, logger, exifWorkers)
go worker.Start()
orchestratorRoute := routes.NewOrchestratorRoute(logger, tplEngine, orchestartor)
orch := work.NewOrchestrator("amqp://guest:guest@localhost:5672/", logger)
directoryWorkQueue := work.NewWorkQueue("directory", orch)
dirWorker := work.NewDirectoryWorker(logger, directoryService)
go orch.StartWorker(dirWorker)
dirRoute := routes.NewDirRoute(logger, tplEngine, directoryService, directoryWorkQueue)
dirFiles := routes.NewFilesRoute(logger, tplEngine, fileService, directoryService, exifWorkers)
// tagRoute := routes.NewTagRoute(logger, tplEngine, tagService)
router.RegisterRoute("/", web.GET, indexRoute)
router.RegisterRoute("/dir", web.GET, dirRoute)
router.RegisterRoute("/dir", web.POST, dirRoute)
router.RegisterRoute("/files/:id", web.GET, dirFiles)
router.RegisterRoute("/files", web.POST, dirFiles)
router.RegisterRoute("/orchestrator", web.GET, orchestratorRoute)
router.RegisterRoute("/orchestrator", web.POST, orchestratorRoute)
// router.RegisterRoute("/tags", web.GET, tagRoute)
// router.RegisterRoute("/tags", web.POST, tagRoute)
genericFileRepo := repository.NewRepository(logger, conn.GetDB(), &genericmodels.File{})
lis, _ := genericFileRepo.FindMany("ParentDirectory", "0xe2a69ec6e12b488eae3ea2cf1084965e")
for _, item := range lis {
fmt.Printf("%+v\n", item)
}
// dir, _ := genericDirRepo.FindOne("Id", "0x4b859d08ddb0442da48c30c038f20df3")
// logger.Info(repository.GetModelFields(&genericmodels.Directory{}))
// metadataRepo := repository.NewRepository(logger, conn.GetDB(), &genericmodels.Metadata{})
// metadataTypeRepo := repository.NewRepository(logger, conn.GetDB(), &genericmodels.MetadataType{})
// metadataTypeService := services.NewMetadataTypeService(logger, metadataTypeRepo)
// metadataService := services.NewMetadataService(logger, metadataRepo, metadataTypeService, "EXIF")
// exifSch := routines.NewExifScheduler(logger, metadataService, *fileService)
// worker := exifSch.Schedule([]string{"0xd10af1c9bde24195825134e3949288bf"})
logger.Fatal(http.ListenAndServe(":8080", router.Router()))
logger.Info("Exiting Application...")
}