-
Notifications
You must be signed in to change notification settings - Fork 370
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
Add redis as an option for database #177
Conversation
func (s *service) Health() map[string]string { | ||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) | ||
defer cancel() | ||
|
||
err := s.db.Ping(ctx) | ||
|
||
if err != nil { | ||
log.Fatalf(fmt.Sprintf("db down: %v", err)) | ||
} | ||
|
||
return map[string]string{ | ||
"message": "It's healthy", | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping is returning an error, and it is breaking the app when you curl the health route.
I think this solves the issue
func (s *service) Health() map[string]string {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
result, err := s.db.Ping(ctx).Result()
if err != nil {
log.Fatalf(fmt.Sprintf("db down: %v", err))
}
if result != "PONG" {
log.Fatalf(fmt.Sprintf("Unexpected ping response: %s", result))
}
return map[string]string{
"message": "It's healthy",
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good catch 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After fixing the Health func, this is ready for merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.
Problem/Feature
Adding Redis as an option for a database.
Description of Changes:
Checklist