Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Replace printf-style function with print-style for dynamic format #317

Merged
merged 4 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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