-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (52 loc) · 1.43 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
package main
import (
"net/http"
"os"
"github.com/sirupsen/logrus"
"awesomeProject/internal"
)
const (
// all of these variables should be set as environment variables
dbHost = "127.0.0.1"
dbPort = "5432"
dbUser = "admin"
dbPassword = "admin"
dbName = "database"
serverAddr = ":8080"
dns = "https://www.ssga.com"
jwtSecret = "something"
)
func main() {
// Initialize a logger
logger := logrus.New()
// Create a new database connection
store, err := internal.NewDatabase(dbHost, dbPort, dbUser, dbPassword, dbName)
if err != nil {
logger.Fatalf("Failed to create a database connection: %v", err)
}
// Get the current working directory
dir, err := os.Getwd()
if err != nil {
logger.Fatalf("Error getting the current working directory: %v", err)
return
}
// Run database migrations
err = store.RunMigrations(dir + "/migrations")
if err != nil {
logger.Fatalf("Failed to run database migrations: %v", err)
}
// Create a new DailyDataUpdater instance
ddu := internal.NewDailyDataUpdater(dns , store, logger)
go ddu.Run()
// Create a new server
server := internal.NewServer(logger, store)
// Create HTTP handlers
handlers := internal.NewHandler(server, jwtSecret)
// Create a router and set up routes
r := internal.MakeHTTPHandler(handlers)
// Start the HTTP server
err = http.ListenAndServe(serverAddr, r)
if err != nil {
logger.Fatalf("Failed to start the HTTP server: %v", err)
}
}