Skip to content

Commit

Permalink
Refactor: Replace printf-style function with print-style for dynamic …
Browse files Browse the repository at this point in the history
…format (#317)
  • Loading branch information
MatthewAraujo authored Oct 28, 2024
1 parent 9f230cd commit ecb9f4a
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/template/dbdriver/files/service/mongo.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *service) Health() map[string]string {

err := s.db.Ping(ctx, nil)
if err != nil {
log.Fatalf(fmt.Sprintf("db down: %v", err))
log.Fatalf("db down: %v", err)
}

return map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion cmd/template/dbdriver/files/service/mysql.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (s *service) Health() map[string]string {
if err != nil {
stats["status"] = "down"
stats["error"] = fmt.Sprintf("db down: %v", err)
log.Fatalf(fmt.Sprintf("db down: %v", err)) // Log the error and terminate the program
log.Fatalf("db down: %v", err) // Log the error and terminate the program
return stats
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/template/dbdriver/files/service/postgres.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s *service) Health() map[string]string {
if err != nil {
stats["status"] = "down"
stats["error"] = fmt.Sprintf("db down: %v", err)
log.Fatalf(fmt.Sprintf("db down: %v", err)) // Log the error and terminate the program
log.Fatalf("db down: %v", err) // Log the error and terminate the program
return stats
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/template/dbdriver/files/service/redis.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
func New() Service {
num, err := strconv.Atoi(database)
if err != nil {
log.Fatalf(fmt.Sprintf("database incorrect %v", err))
log.Fatalf("database incorrect %v", err)
}

fullAddress := fmt.Sprintf("%s:%s", address, port)
Expand Down Expand Up @@ -70,7 +70,7 @@ func (s *service) Health() map[string]string {
func (s *service) checkRedisHealth(ctx context.Context, stats map[string]string) map[string]string {
// Ping the Redis server to check its availability.
pong, err := s.db.Ping(ctx).Result()
// Note: By extracting and simplifying like this, `log.Fatalf(fmt.Sprintf("db down: %v", err))`
// Note: By extracting and simplifying like this, `log.Fatalf("db down: %v", err)`
// can be changed into a standard error instead of a fatal error.
if err != nil {
log.Fatalf(fmt.Sprintf("db down: %v", err))
Expand Down
2 changes: 1 addition & 1 deletion cmd/template/dbdriver/files/service/sqlite.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *service) Health() map[string]string {
if err != nil {
stats["status"] = "down"
stats["error"] = fmt.Sprintf("db down: %v", err)
log.Fatalf(fmt.Sprintf("db down: %v", err)) // Log the error and terminate the program
log.Fatalf("db down: %v", err) // Log the error and terminate the program
return stats
}

Expand Down
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@
- kobamkode
- mikelerch
- MohammadAlhallaq
- MatthewAraujo
2 changes: 1 addition & 1 deletion docs/docs/endpoints-test/mongo.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *service) Health() map[string]string {

err := s.db.Ping(ctx, nil)
if err != nil {
log.Fatalf(fmt.Sprintf("db down: %v", err))
log.Fatalf("db down: %v", err)
}

return map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/endpoints-test/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (s *service) Health() map[string]string {
func (s *service) checkRedisHealth(ctx context.Context, stats map[string]string) map[string]string {
pong, err := s.db.Ping(ctx).Result()
if err != nil {
log.Fatalf(fmt.Sprintf("db down: %v", err))
log.Fatalf("db down: %v", err)
}

stats["redis_status"] = "up"
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/endpoints-test/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *service) Health() map[string]string {
if err != nil {
stats["status"] = "down"
stats["error"] = fmt.Sprintf("db down: %v", err)
log.Fatalf(fmt.Sprintf("db down: %v", err))
log.Fatalf("db down: %v", err)
return stats
}

Expand Down

0 comments on commit ecb9f4a

Please sign in to comment.