Skip to content

Commit

Permalink
reuse exit function
Browse files Browse the repository at this point in the history
Signed-off-by: SammyOina <sammyoina@gmail.com>
  • Loading branch information
SammyOina committed Jul 19, 2023
1 parent 3b7fcf4 commit d644cac
Show file tree
Hide file tree
Showing 24 changed files with 31 additions and 69 deletions.
4 changes: 1 addition & 3 deletions cmd/bootstrap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer db.Close()

// Create new redis client for bootstrap event store
Expand Down
4 changes: 1 addition & 3 deletions cmd/cassandra-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer tcHandler.Close()
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())

Expand Down
4 changes: 1 addition & 3 deletions cmd/cassandra-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer csdSession.Close()

tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID)
Expand Down
4 changes: 1 addition & 3 deletions cmd/certs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer db.Close()

auth, authHandler, err := authClient.Setup(envPrefix, svcName)
Expand Down
4 changes: 1 addition & 3 deletions cmd/coap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer tcHandler.Close()
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())

Expand Down
4 changes: 1 addition & 3 deletions cmd/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer tcHandler.Close()
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())

Expand Down
4 changes: 1 addition & 3 deletions cmd/influxdb-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer tcHandler.Close()
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())

Expand Down
4 changes: 1 addition & 3 deletions cmd/influxdb-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ func main() {
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer func() {
if err := tp.Shutdown(ctx); err != nil {
logger.Error(fmt.Sprintf("Error shutting down tracer provider: %v", err))
Expand Down
4 changes: 1 addition & 3 deletions cmd/lora/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ func main() {
logger.Fatal(fmt.Sprintf("failed to setup route map redis client : %s", err))
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer rmConn.Close()

tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID)
Expand Down
4 changes: 1 addition & 3 deletions cmd/mongodb-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer tcHandler.Close()
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())

Expand Down
4 changes: 1 addition & 3 deletions cmd/mongodb-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ func main() {
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer func() {
if err := tp.Shutdown(ctx); err != nil {
logger.Error(fmt.Sprintf("Error shutting down tracer provider: %v", err))
Expand Down
4 changes: 1 addition & 3 deletions cmd/mqtt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ func main() {
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer func() {
if err := tp.Shutdown(ctx); err != nil {
logger.Error(fmt.Sprintf("Error shutting down tracer provider: %v", err))
Expand Down
4 changes: 1 addition & 3 deletions cmd/opcua/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ func main() {
logger.Fatal(fmt.Sprintf("failed to setup %s bootstrap event store redis client : %s", svcName, err))
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer esConn.Close()

tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID)
Expand Down
4 changes: 1 addition & 3 deletions cmd/postgres-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ func main() {
}

var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer tcHandler.Close()
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())

Expand Down
4 changes: 1 addition & 3 deletions cmd/postgres-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ func main() {
logger.Error(fmt.Sprintf("Failed to init Jaeger: %s", err))
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer func() {
if err := tp.Shutdown(ctx); err != nil {
logger.Error(fmt.Sprintf("Error shutting down tracer provider: %v", err))
Expand Down
4 changes: 1 addition & 3 deletions cmd/smpp-notifier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer db.Close()

smppConfig := mfsmpp.Config{}
Expand Down
4 changes: 1 addition & 3 deletions cmd/smtp-notifier/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer db.Close()

ec := email.Config{}
Expand Down
4 changes: 1 addition & 3 deletions cmd/things/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer db.Close()

tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID)
Expand Down
4 changes: 1 addition & 3 deletions cmd/timescale-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer db.Close()

repo := newService(db, logger)
Expand Down
4 changes: 1 addition & 3 deletions cmd/timescale-writer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer db.Close()

tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID)
Expand Down
4 changes: 1 addition & 3 deletions cmd/twins/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer cacheClient.Close()

// Setup new redis event store client
Expand Down
4 changes: 1 addition & 3 deletions cmd/users/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer db.Close()

tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID)
Expand Down
4 changes: 1 addition & 3 deletions cmd/ws/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ func main() {
logger.Fatal(err.Error())
}
var exitCode int
defer func() {
os.Exit(exitCode)
}()
defer mflog.ExitWithError(&exitCode)
defer internal.Close(logger, tcHandler)
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())

Expand Down
8 changes: 8 additions & 0 deletions logger/exit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package logger

import "os"

// ExitWithError closes the current process with error code.
func ExitWithError(code *int) {
os.Exit(*code)

Check warning on line 7 in logger/exit.go

View check run for this annotation

Codecov / codecov/patch

logger/exit.go#L6-L7

Added lines #L6 - L7 were not covered by tests
}

0 comments on commit d644cac

Please sign in to comment.