1
0
mirror of https://github.com/raseels-repos/golang-saas-starter-kit.git synced 2025-07-03 00:58:13 +02:00
Files
example-project
cmd
schema
web-api
docs
handlers
account.go
check.go
project.go
routes.go
signup.go
user.go
user_account.go
templates
tests
.gitignore
Dockerfile
README.md
ecs-task-definition.json
main.go
sample.env
web-app
docker
internal
tools
.gitignore
.gitlab-ci.yml
README.md
docker-compose.yaml
go.mod
go.sum
sample.env_docker_compose
.gitignore
CONTRIBUTORS
LICENSE
README.md

52 lines
1.2 KiB
Go
Raw Normal View History

package handlers
import (
"context"
"net/http"
"geeks-accelerator/oss/saas-starter-kit/example-project/internal/platform/web"
2019-05-23 14:32:24 -05:00
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
"gopkg.in/DataDog/dd-trace-go.v1/contrib/go-redis/redis"
)
// Check provides support for orchestration health checks.
type Check struct {
2019-05-23 14:32:24 -05:00
MasterDB *sqlx.DB
Redis *redis.Client
// ADD OTHER STATE LIKE THE LOGGER IF NEEDED.
}
// Health validates the service is healthy and ready to accept requests.
func (c *Check) Health(ctx context.Context, w http.ResponseWriter, r *http.Request, params map[string]string) error {
// check postgres
2019-05-23 14:32:24 -05:00
_, err := c.MasterDB.Exec("SELECT 1")
if err != nil {
return errors.Wrap(err, "Postgres failed")
}
// check redis
2019-07-10 16:24:10 -08:00
err = c.Redis.Ping().Err()
if err != nil {
return errors.Wrap(err, "Redis failed")
}
status := struct {
Status string `json:"status"`
}{
Status: "ok",
}
2019-05-23 14:32:24 -05:00
return web.RespondJson(ctx, w, status, http.StatusOK)
}
2019-07-10 16:24:10 -08:00
// Ping validates the service is ready to accept requests.
func (c *Check) Ping(ctx context.Context, w http.ResponseWriter, r *http.Request, params map[string]string) error {
status := "pong"
return web.RespondJson(ctx, w, status, http.StatusOK)
}