Bliblioteca de health check em Golang.
- MongoDB;
- RabbitMQ.
- SQL Server.
$ go get github.com/mundipagg/healthcheck-go
$ govendor add github.com/mundipagg/healthcheck-go
$ govendor add github.com/mundipagg/healthcheck-go/checks
$ govendor add github.com/mundipagg/healthcheck-go/checks/mongo
$ govendor add github.com/mundipagg/healthcheck-go/checks/rabbit
package healthcheck
import (
"github.com/gin-gonic/gin"
"github.com/mundipagg/boleto-api/config"
HealthCheckLib "github.com/mundipagg/healthcheck-go"
"github.com/mundipagg/healthcheck-go/checks/mongo"
"github.com/mundipagg/healthcheck-go/checks/rabbit"
)
func createHealthCheck() HealthCheckLib.HealthCheck {
mongoConfig := &mongo.Config{
Url: config.Get().MongoURL,
User: config.Get().MongoUser,
Password: config.Get().MongoPassword,
Database: config.Get().MongoDatabase,
AuthSource: config.Get().MongoAuthSource,
Timeout: 3,
ForceTLS: config.Get().ForceTLS,
MaxPoolSize: 100,
}
rabbitConfig := &rabbit.Config{
ConnectionString: config.Get().ConnQueue,
}
healthCheck := HealthCheckLib.New()
healthCheck.AddService(mongoConfig)
healthCheck.AddService(rabbitConfig)
return healthCheck
}
func Endpoint(c *gin.Context) {
healthcheck := createHealthCheck()
c.JSON(200, healthcheck.Execute())
}
package api
import (
"github.com/gin-gonic/gin"
"github.com/mundipagg/boleto-api/healthcheck"
)
func Base(router *gin.Engine) {
router.GET("/healthcheck", healthcheck.Endpoint)
}
{
"status": "Healthy",
"results": {
"mongo": {
"status": "Healthy",
"description": "mongo is healthy"
},
"rabbit": {
"status": "Healthy",
"description": "rabbit is healthy"
}
}
}