Refactor project structure: enhance tests, improve server shutdown, expand CI checks, and update UI for better event presentation.
This commit is contained in:
@@ -1,17 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
diun "awesomeProject/pkg/diunwebhook"
|
||||
)
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/webhook", diun.WebhookHandler)
|
||||
http.HandleFunc("/api/updates", diun.UpdatesHandler)
|
||||
http.Handle("/", http.FileServer(http.Dir("./static")))
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
|
||||
log.Println("Listening on :8080")
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/webhook", diun.WebhookHandler)
|
||||
mux.HandleFunc("/api/updates", diun.UpdatesHandler)
|
||||
mux.Handle("/", http.FileServer(http.Dir("./static")))
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: ":" + port,
|
||||
Handler: mux,
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
IdleTimeout: 60 * time.Second,
|
||||
}
|
||||
|
||||
stop := make(chan os.Signal, 1)
|
||||
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
log.Printf("Listening on :%s", port)
|
||||
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
log.Fatalf("ListenAndServe: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
<-stop
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if err := srv.Shutdown(ctx); err != nil {
|
||||
log.Printf("Shutdown error: %v", err)
|
||||
} else {
|
||||
log.Println("Server stopped cleanly")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user