Replaced the gin framwwork with echo
This commit is contained in:
1 parent
8e2d22b899
commit
034ba35fbb
32 files changed
+347
-265
No files matched your search
+54
-6
@@ -1,17 +1,65 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"music-server/internal/server"
|
||||
"music-server/pkg/conf"
|
||||
"net/http"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
//go:embed swagger
|
||||
var swagger embed.FS
|
||||
func gracefulShutdown(apiServer *http.Server, done chan bool) {
|
||||
// Create context that listens for the interrupt signal from the OS.
|
||||
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
// Listen for the interrupt signal.
|
||||
<-ctx.Done()
|
||||
|
||||
log.Println("shutting down gracefully, press Ctrl+C again to force")
|
||||
conf.CloseDb()
|
||||
|
||||
// The context is used to inform the server it has 5 seconds to finish
|
||||
// the request it is currently handling
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if err := apiServer.Shutdown(ctx); err != nil {
|
||||
log.Printf("Server forced to shutdown with error: %v", err)
|
||||
}
|
||||
|
||||
log.Println("Server exiting")
|
||||
|
||||
// Notify the main goroutine that the shutdown is complete
|
||||
done <- true
|
||||
}
|
||||
|
||||
func main() {
|
||||
conf.SetupDb()
|
||||
|
||||
conf.SetupRestServer(swagger)
|
||||
server := server.NewServer()
|
||||
|
||||
conf.CloseDb()
|
||||
// Create a done channel to signal when the shutdown is complete
|
||||
done := make(chan bool, 1)
|
||||
|
||||
// Run graceful shutdown in a separate goroutine
|
||||
go gracefulShutdown(server, done)
|
||||
|
||||
log.Printf("Open http://localhost%s in the browser", server.Addr)
|
||||
err := server.ListenAndServe()
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
panic(fmt.Sprintf("http server error: %s", err))
|
||||
}
|
||||
|
||||
// Wait for the graceful shutdown to complete
|
||||
<-done
|
||||
log.Println("Graceful shutdown complete.")
|
||||
|
||||
//conf.SetupDb()
|
||||
|
||||
//conf.SetupRestServer(swagger)
|
||||
|
||||
//conf.CloseDb()
|
||||
}
|
||||
+4
-1
@@ -3,4 +3,7 @@ package web
|
||||
import "embed"
|
||||
|
||||
//go:embed "assets"
|
||||
var Files embed.FS
|
||||
var Assets embed.FS
|
||||
|
||||
//go:embed "swagger"
|
||||
var Swagger embed.FS
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user