I am batman
This commit is contained in:
74
cmd/api/main.go
Normal file
74
cmd/api/main.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"OpsMastery.v5/internal/database"
|
||||
"OpsMastery.v5/internal/oauth"
|
||||
"OpsMastery.v5/internal/server"
|
||||
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
)
|
||||
|
||||
func gracefulShutdown(fiberServer *server.FiberServer, done chan bool) {
|
||||
// Create context that listens for the interrupt signal from the OS.
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
// Listen for the interrupt signal.
|
||||
<-ctx.Done()
|
||||
|
||||
log.Println("shutting down gracefully, press Ctrl+C again to force")
|
||||
stop() // Allow Ctrl+C to force shutdown
|
||||
|
||||
// The context is used to inform the server it has 5 seconds to finish
|
||||
// the request it is currently handling
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if err := fiberServer.ShutdownWithContext(ctx); err != nil {
|
||||
log.Printf("Server forced to shutdown with error: %v", err)
|
||||
}
|
||||
|
||||
log.Println("Server exiting")
|
||||
|
||||
// Notify the main goroutine that the shutdown is complete
|
||||
done <- true
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Initialize the database (if not already done elsewhere)
|
||||
database.Init()
|
||||
|
||||
// Initialize OAuth providers (Google, GitHub, etc.)
|
||||
oauth.InitProviders()
|
||||
|
||||
server := server.New()
|
||||
|
||||
// Pass the global db instance to RegisterFiberRoutes
|
||||
server.RegisterFiberRoutes(database.DB())
|
||||
|
||||
// Create a done channel to signal when the shutdown is complete
|
||||
done := make(chan bool, 1)
|
||||
|
||||
go func() {
|
||||
port, _ := strconv.Atoi(os.Getenv("PORT"))
|
||||
err := server.Listen(fmt.Sprintf(":%d", port))
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("http server error: %s", err))
|
||||
}
|
||||
}()
|
||||
|
||||
// Run graceful shutdown in a separate goroutine
|
||||
go gracefulShutdown(server, done)
|
||||
|
||||
// Wait for the graceful shutdown to complete
|
||||
<-done
|
||||
log.Println("Graceful shutdown complete.")
|
||||
}
|
||||
7
cmd/chat-service/main.go
Normal file
7
cmd/chat-service/main.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "OpsMastery.v5/internal/chat_service"
|
||||
|
||||
func main() {
|
||||
chat_service.Start()
|
||||
}
|
||||
11
cmd/seed/main.go
Normal file
11
cmd/seed/main.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"OpsMastery.v5/dev"
|
||||
"OpsMastery.v5/internal/database"
|
||||
)
|
||||
|
||||
func main() {
|
||||
database.Init()
|
||||
dev.Seed(database.DB())
|
||||
}
|
||||
7
cmd/webrtc-service/main.go
Normal file
7
cmd/webrtc-service/main.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "OpsMastery.v5/internal/webrtc_service"
|
||||
|
||||
func main() {
|
||||
webrtc_service.StartSignalingServer()
|
||||
}
|
||||
Reference in New Issue
Block a user