Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
VILLASframework
VILLASweb-backend-go
Commits
b78dc396
Commit
b78dc396
authored
Nov 12, 2019
by
Sonja Happ
Browse files
initial version of healthz endpoint
parent
e8b7508b
Changes
2
Hide whitespace changes
Inline
Side-by-side
amqp/amqpclient.go
View file @
b78dc396
...
...
@@ -163,3 +163,12 @@ func PingAMQP() error {
err
:=
SendActionAMQP
(
a
,
""
)
return
err
}
func
CheckConnection
()
error
{
if
client
.
connection
.
IsClosed
()
{
return
fmt
.
Errorf
(
"connection to broker is closed"
)
}
return
nil
}
routes/healthz/healthz_endpoint.go
0 → 100644
View file @
b78dc396
package
healthz
import
(
"git.rwth-aachen.de/acs/public/villas/web-backend-go/amqp"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
"github.com/gin-gonic/gin"
"net/http"
)
func
RegisterHealthzEndpoint
(
r
*
gin
.
RouterGroup
)
{
r
.
GET
(
""
,
getHealth
)
}
// getHealth godoc
// @Summary Get health status of backend
// @ID getHealth
// @Produce json
// @Tags healthz
// @Success 200 "Backend is healthy, database and AMQP broker connections are alive"
// @Failure 500 "Backend is NOT healthy"
// @Router /healthz [get]
func
getHealth
(
c
*
gin
.
Context
)
{
// check if DB connection is active
db
:=
database
.
GetDB
()
err
:=
db
.
DB
()
.
Ping
()
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"message"
:
err
})
}
// check if connection to AMQP broker is alive if backend was started with AMQP client
if
len
(
database
.
AMQP_URL
)
!=
0
{
err
=
amqp
.
CheckConnection
()
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"message"
:
err
})
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{})
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment