main.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package main
  2. import (
  3. "byom-infra-api/config"
  4. "byom-infra-api/handlers"
  5. "byom-infra-api/routes"
  6. "log"
  7. "net/http"
  8. "github.com/gorilla/mux"
  9. )
  10. func main() {
  11. // Initialize the OVH client configuration for API interactions
  12. config.InitOVHClient()
  13. // Initialize the BYOM configuration file
  14. err := config.InitByomConfig()
  15. if err != nil {
  16. log.Fatalf("Failed to initialize config: %v", err)
  17. }
  18. log.Printf("BYOM Config initialized successfully")
  19. // Load all handlers from the handlers package
  20. log.Printf("Loading handlers...")
  21. dnshandler := handlers.NewDNSHandler()
  22. // Create a new Gorilla Mux router instance for handling HTTP requests
  23. r := mux.NewRouter()
  24. // Configure all application routes and their handlers
  25. routes.SetupRoutes(r, dnshandler)
  26. log.Println("Routes configured...")
  27. // Start the HTTP server on port 8080
  28. // Log server startup message
  29. log.Println("Server starting on port 8080...")
  30. // Listen and serve HTTP requests, log fatal error if server fails to start
  31. if err := http.ListenAndServe(":8080", r); err != nil {
  32. log.Fatal(err)
  33. }
  34. }