- Add initial project scaffolding with Go module and project structure - Create server and CLI entry points for application - Implement Makefile with development and build commands - Add `.env.example` with comprehensive configuration template - Set up README.md with project documentation and setup instructions - Configure basic dependencies for server, database, and CLI tools - Establish internal package structure for models, services, and handlers - Add initial configuration and environment management - Prepare for HTTP server, CLI, and database integration
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"attune-heart-therapy/internal/config"
|
|
"attune-heart-therapy/internal/server"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
func main() {
|
|
// Load environment variables
|
|
if err := godotenv.Load(); err != nil {
|
|
log.Println("No .env file found, using system environment variables")
|
|
}
|
|
|
|
// Load configuration
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
log.Fatalf("Failed to load configuration: %v", err)
|
|
}
|
|
|
|
// Initialize server
|
|
srv := server.New(cfg)
|
|
|
|
// Setup graceful shutdown
|
|
quit := make(chan os.Signal, 1)
|
|
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
// Start server in a goroutine
|
|
go func() {
|
|
if err := srv.Start(); err != nil && err != http.ErrServerClosed {
|
|
log.Fatalf("Failed to start server: %v", err)
|
|
}
|
|
}()
|
|
|
|
log.Println("Server started successfully")
|
|
|
|
// Wait for interrupt signal
|
|
<-quit
|
|
log.Println("Shutting down server...")
|
|
|
|
// Create a deadline for shutdown
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
defer cancel()
|
|
|
|
// Shutdown server gracefully
|
|
if err := srv.Shutdown(); err != nil {
|
|
log.Printf("Error during server shutdown: %v", err)
|
|
}
|
|
|
|
// Wait for context deadline or completion
|
|
<-ctx.Done()
|
|
log.Println("Server shutdown completed")
|
|
}
|