Files
monaco/backend/main.go
2025-03-21 22:27:46 +05:30

40 lines
1.0 KiB
Go

package main
import (
"log"
"net/http"
"os"
"time"
"github.com/arnab-afk/monaco/handler"
)
func main() {
// Configure logging with timestamps and file locations
log.SetFlags(log.LstdFlags | log.Lshortfile)
log.SetOutput(os.Stdout)
log.Println("Starting Monaco code execution backend...")
h := handler.NewHandler()
// Create a middleware for request logging
loggingMiddleware := func(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
startTime := time.Now()
log.Printf("[HTTP] %s %s %s", r.Method, r.URL.Path, r.RemoteAddr)
next(w, r)
log.Printf("[HTTP] %s %s completed in %v", r.Method, r.URL.Path, time.Since(startTime))
}
}
// Register handlers with logging middleware
http.HandleFunc("/submit", loggingMiddleware(h.SubmitHandler))
http.HandleFunc("/status", loggingMiddleware(h.StatusHandler))
http.HandleFunc("/result", loggingMiddleware(h.ResultHandler))
port := ":8080"
log.Printf("Server started at %s", port)
log.Fatal(http.ListenAndServe(port, nil))
}