add version handler (#287)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
ffd55152e5
commit
f960f942f2
|
@ -36,6 +36,13 @@ func heartbeatHandler(c *gin.Context) {
|
|||
c.AbortWithStatus(200)
|
||||
}
|
||||
|
||||
func versionHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"source": "https://github.com/appleboy/gorush",
|
||||
"version": GetVersion(),
|
||||
})
|
||||
}
|
||||
|
||||
func pushHandler(c *gin.Context) {
|
||||
var form RequestPush
|
||||
var msg string
|
||||
|
@ -112,6 +119,7 @@ func routerEngine() *gin.Engine {
|
|||
r.POST(PushConf.API.PushURI, pushHandler)
|
||||
r.GET(PushConf.API.MetricURI, metricsHandler)
|
||||
r.GET("/healthz", heartbeatHandler)
|
||||
r.GET("/version", versionHandler)
|
||||
r.GET("/", rootHandler)
|
||||
|
||||
return r
|
||||
|
|
|
@ -268,6 +268,23 @@ func TestHeartbeatHandler(t *testing.T) {
|
|||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
})
|
||||
}
|
||||
|
||||
func TestVersionHandler(t *testing.T) {
|
||||
SetVersion("3.0.0")
|
||||
initTest()
|
||||
|
||||
r := gofight.New()
|
||||
|
||||
r.GET("/version").
|
||||
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
|
||||
assert.Equal(t, http.StatusOK, r.Code)
|
||||
data := []byte(r.Body.String())
|
||||
|
||||
value, _ := jsonparser.GetString(data, "version")
|
||||
|
||||
assert.Equal(t, "3.0.0", value)
|
||||
})
|
||||
}
|
||||
func TestDisabledHTTPServer(t *testing.T) {
|
||||
initTest()
|
||||
PushConf.Core.Enabled = false
|
||||
|
|
Loading…
Reference in New Issue