feat: Create collection file for routes

This commit is contained in:
Björn Benouarets
2025-08-11 22:15:32 +02:00
commit f00ecb8155
14 changed files with 482 additions and 0 deletions

39
server/api.go Normal file
View File

@@ -0,0 +1,39 @@
package server
import (
"errors"
"fmt"
"net/http"
"time"
"github.com/tenante/api/database"
)
type ApiServer struct {
Port int
DatabaseConnection *database.Connection
}
func NewApiServer(port int, database *database.Connection) *ApiServer {
return &ApiServer{Port: port, DatabaseConnection: database}
}
func (api *ApiServer) Start() error {
mux := http.NewServeMux()
mux.HandleFunc("/_/health", api.HealthCheckRoute)
srv := &http.Server{
Addr: fmt.Sprintf(":%d", api.Port),
Handler: mux,
ReadTimeout: 15 * time.Second,
WriteTimeout: 15 * time.Second,
IdleTimeout: 60 * time.Second,
}
fmt.Printf("🚀 Server starting on %s...\n", srv.Addr)
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
return err
}
return nil
}