From dac4e098544be661f3ec4dd402c15b4af35012d8 Mon Sep 17 00:00:00 2001 From: Christopher James Hayward Date: Sat, 8 Jul 2023 12:28:47 -0400 Subject: [PATCH] Use log instead of fmt for errors --- cmd/gateway/main.go | 6 +++--- cmd/server/main.go | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/gateway/main.go b/cmd/gateway/main.go index 7aa627a..c97d405 100644 --- a/cmd/gateway/main.go +++ b/cmd/gateway/main.go @@ -24,7 +24,7 @@ func main() { // Create the connection to the server. conn, err := grpc.Dial(fmt.Sprintf("%s:%d", *serverAddr, *serverPort)) if err != nil { - fmt.Printf("Failed to connect: %v", err) + log.Fatal(err) } // Defer closing the connection. @@ -41,8 +41,8 @@ func main() { http.HandleFunc("/change_password", gateway.ChangePassword(client)) // Listen for requests. - fmt.Printf("Forwarding from :%d to %s:%d", *port, *serverAddr, *serverPort) + log.Printf("Forwarding from :%d to %s:%d", *port, *serverAddr, *serverPort) if err := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil); err != nil { - fmt.Printf("Failed to listen: %v", err) + log.Fatal(err) } } diff --git a/cmd/server/main.go b/cmd/server/main.go index 661423f..f66beda 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "log" "net" "git.chrishayward.xyz/x/users/proto" @@ -33,7 +34,7 @@ func main() { // If the secret has not been set print it to the console. if *secret == secretDefault { - fmt.Printf("SECRET=%s\n", secretDefault) + log.Printf("SECRET=%s\n", secretDefault) } // Initialize the database. @@ -52,12 +53,12 @@ func main() { // Create the network listener. lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) if err != nil { - fmt.Printf("Failed to listen: %v", err) + log.Fatal(err) } // Start listening for requests. srv := grpc.NewServer() proto.RegisterUsersServer(srv, server.NewUsersServer(secret, db)) - fmt.Printf("Listening on :%d", *port) + log.Printf("Listening on :%d", *port) srv.Serve(lis) }