-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (34 loc) · 969 Bytes
/
main.go
File metadata and controls
40 lines (34 loc) · 969 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
package main
import (
"log"
"os"
"path/filepath"
// Aliasing to avoid conflict
_ "github.com/golang-migrate/migrate/v4/source/file"
"github.com/shibbirmcc/user-auth-and-permissions/config"
"github.com/shibbirmcc/user-auth-and-permissions/initializer"
// Aliasing to avoid conflict
)
func main() {
absEnvPath, err := filepath.Abs(".env")
if err != nil {
log.Fatalf("Error finding absolute path of .env.test: %v", err)
}
config.LoadEnv(absEnvPath)
db, err := config.GetDatabase()
if err != nil {
os.Exit(1)
}
initializer.ApplyMigrations(db, "migrations")
userRegService, userLoginService := initializer.InitializeServices(db)
userHandler := initializer.InitializeHandlers(userRegService, userLoginService)
router := initializer.SetupRouter(userHandler)
// Start the server
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
if err := router.Run(":" + port); err != nil {
log.Fatalf("Failed to start the server: %v", err)
}
}