Skip to content

Commit

Permalink
fixes log handling
Browse files Browse the repository at this point in the history
Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
  • Loading branch information
NishantBansal2003 committed Jan 26, 2025
1 parent 95c5ecd commit ee04e98
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go-twilio/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func gracefulShutdown(router *gin.Engine) {

// The context is used to inform the server it has 5 seconds to complete the ongoing requests
if err := srv.Shutdown(context.TODO()); err != nil {
log.Fatal("Server forced to shutdown:", err)
fmt.Fprintf(os.Stderr, "Server forced to shutdown: %v\n", err)
}

fmt.Println("Server exiting")
Expand Down
3 changes: 2 additions & 1 deletion graphql-sql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"database/sql"
"fmt"
"log"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -61,7 +62,7 @@ func main() {
defer func() {
err = db.Close()
if err != nil {
panic(err)
log.Println(err)
}
}()

Expand Down
2 changes: 1 addition & 1 deletion mux-elasticsearch/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (a *App) Run(port string) {
defer cancel()

if err := a.Server.Shutdown(ctx); err != nil {
log.Fatalf("Server forced to shutdown: %v", err)
fmt.Fprintf(os.Stderr, "Server forced to shutdown: %v\n", err)
}

log.Println("Server exiting")
Expand Down
7 changes: 4 additions & 3 deletions mux-mysql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main
import (
"context"
"database/sql"
"fmt"
"log"
"net/http"
"os"
Expand All @@ -29,7 +30,7 @@ func main() {
defer func() {
err = store.Close()
if err != nil {
log.Fatal(err)
fmt.Fprintf(os.Stderr, "Could not close database connection: %v\n", err)
}
}()

Expand Down Expand Up @@ -62,11 +63,11 @@ func main() {
defer cancel()

if err := server.Shutdown(ctx); err != nil {
log.Fatalf("Could not gracefully shutdown the server: %v\n", err)
fmt.Fprintf(os.Stderr, "Could not gracefully shutdown the server: %v\n", err)
}

if err := store.Close(); err != nil {
log.Fatalf("Could not close database connection: %v\n", err)
fmt.Fprintf(os.Stderr, "Could not close database connection: %v\n", err)
}

log.Println("Server stopped")
Expand Down
2 changes: 1 addition & 1 deletion mux-sql/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (a *App) Run(addr string) {
defer cancel()

if err := a.Server.Shutdown(ctx); err != nil {
log.Fatalf("Server forced to shutdown: %v", err)
fmt.Fprintf(os.Stderr, "Server forced to shutdown: %v\n", err)
}

log.Println("Server exiting")
Expand Down
4 changes: 2 additions & 2 deletions sse-svelte/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func main() {
defer func() {
err = client.Disconnect(context.Background())
if err != nil {
log.Fatal(err)
log.Println(err)
}
}()

Expand Down Expand Up @@ -137,7 +137,7 @@ func main() {
defer cancel()

if err := server.Shutdown(ctx); err != nil {
log.Fatalf("Could not gracefully shutdown the server: %v\n", err)
fmt.Fprintf(os.Stderr, "Could not gracefully shutdown the server: %v\n", err)
}

fmt.Println("Server stopped")
Expand Down
3 changes: 2 additions & 1 deletion users-profile/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main

import (
"context"
"fmt"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -52,7 +53,7 @@ func main() {

// Attempt graceful shutdown by shutting down the server
if err := server.Shutdown(ctx); err != nil {
log.Fatalf("Server shutdown failed: %v", err)
fmt.Fprintf(os.Stderr, "Server shutdown failed: %v\n", err)
}

log.Println("Server gracefully stopped")
Expand Down

0 comments on commit ee04e98

Please # to comment.