-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (36 loc) · 911 Bytes
/
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
package main
import (
"crypto-watchlist-api/db"
"crypto-watchlist-api/routes"
"fmt"
"log"
"net/http"
"os"
"github.com/joho/godotenv"
)
func main() {
fmt.Println("Crypto Watchlist API Server Started")
// Initialize database
err := db.InitDB()
if err != nil {
log.Fatalf("Error initializing database: %v", err)
}
fmt.Println("Database initialized successfully")
// Setup routes
routes.SetupUserRoutes()
routes.SetupSampleRoutes()
// Load .env file
if err := godotenv.Load(); err != nil {
log.Printf("Warning: .env file not found")
}
// Get PORT from environment variable, default to 8080 if not set
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
// Start the server using PORT from env
fmt.Printf("Server is running on http://localhost:%s\n", port)
if err := http.ListenAndServe(":"+port, nil); err != nil {
fmt.Printf("Error starting server: %v\n", err)
}
}