Browse Source

Use log instead of fmt for errors

master
parent
commit
dac4e09854
Signed by: chris GPG Key ID: 3025DCBD46F81C0F
  1. 6
      cmd/gateway/main.go
  2. 7
      cmd/server/main.go

6
cmd/gateway/main.go

@ -24,7 +24,7 @@ func main() {
// Create the connection to the server. // Create the connection to the server.
conn, err := grpc.Dial(fmt.Sprintf("%s:%d", *serverAddr, *serverPort)) conn, err := grpc.Dial(fmt.Sprintf("%s:%d", *serverAddr, *serverPort))
if err != nil { if err != nil {
fmt.Printf("Failed to connect: %v", err)
log.Fatal(err)
} }
// Defer closing the connection. // Defer closing the connection.
@ -41,8 +41,8 @@ func main() {
http.HandleFunc("/change_password", gateway.ChangePassword(client)) http.HandleFunc("/change_password", gateway.ChangePassword(client))
// Listen for requests. // 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 { if err := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil); err != nil {
fmt.Printf("Failed to listen: %v", err)
log.Fatal(err)
} }
} }

7
cmd/server/main.go

@ -3,6 +3,7 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"log"
"net" "net"
"git.chrishayward.xyz/x/users/proto" "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 the secret has not been set print it to the console.
if *secret == secretDefault { if *secret == secretDefault {
fmt.Printf("SECRET=%s\n", secretDefault)
log.Printf("SECRET=%s\n", secretDefault)
} }
// Initialize the database. // Initialize the database.
@ -52,12 +53,12 @@ func main() {
// Create the network listener. // Create the network listener.
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
if err != nil { if err != nil {
fmt.Printf("Failed to listen: %v", err)
log.Fatal(err)
} }
// Start listening for requests. // Start listening for requests.
srv := grpc.NewServer() srv := grpc.NewServer()
proto.RegisterUsersServer(srv, server.NewUsersServer(secret, db)) proto.RegisterUsersServer(srv, server.NewUsersServer(secret, db))
fmt.Printf("Listening on :%d", *port)
log.Printf("Listening on :%d", *port)
srv.Serve(lis) srv.Serve(lis)
} }
Loading…
Cancel
Save