-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (51 loc) · 1.65 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
package main
import (
"log"
"github.com/gofiber/fiber/v2"
"github.com/prashant42b/trademarks-elastic-search-engine/bulkinsert"
"github.com/prashant42b/trademarks-elastic-search-engine/config"
"github.com/prashant42b/trademarks-elastic-search-engine/database"
"github.com/prashant42b/trademarks-elastic-search-engine/router"
"github.com/prashant42b/trademarks-elastic-search-engine/utils"
"github.com/prashant42b/trademarks-elastic-search-engine/utils/conversion_utils"
"github.com/spf13/viper"
)
func main() {
//loads env data into config
utils.ImportENV()
config.LoadConfig()
//start a new fiber app
app := fiber.New()
// Use the log package in Fiber middleware
app.Use(func(c *fiber.Ctx) error {
// Log the request method and path
log.Printf("Request received - Method: %s, Path: %s", c.Method(), c.Path())
// Continue to the next middleware or route handler
return c.Next()
})
//Establishes connection to postgres db and elastic_search
database.ConnectDB()
database.EstablishESConnection()
if viper.GetBool("XML_TO_JSON") {
//Unzips XML file from archive
conversion_utils.UnzipXML(config.ZIP_NAME, config.XML_TARGET_FOLDER)
// Extract xml to json
conversion_utils.CleanAndConvert(config.XML_PATH)
}
if viper.GetBool("AUTO_MIGRATE") {
//Migrates gorm model to postgres db
database.AutoMigrateDB()
}
if viper.GetBool("BULK_INSERT") {
//Bulk inserts jsonData into postgres table
bulkinsert.BulkInsertJsonIntoDB()
//bulkinsert.BulkInsertJsonIntoESDB()
}
//Redirects the app to endpoints defined for the api
router.SetupRoutes(app)
//Listens on port 3000
err := app.Listen(":3000")
if err != nil {
log.Fatal(err)
}
}