kojiapi: add /status route
It works the same way as in the worker API. It's very handy when we just want to test whether the API is up and running.
This commit is contained in:
parent
28aff2259a
commit
c6b5dd8977
3 changed files with 47 additions and 0 deletions
|
|
@ -57,6 +57,11 @@ type Repository struct {
|
|||
Gpgkey string `json:"gpgkey"`
|
||||
}
|
||||
|
||||
// Status defines model for Status.
|
||||
type Status struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// PostComposeJSONBody defines parameters for PostCompose.
|
||||
type PostComposeJSONBody ComposeRequest
|
||||
|
||||
|
|
@ -71,6 +76,9 @@ type ServerInterface interface {
|
|||
// The status of a compose
|
||||
// (GET /compose/{id})
|
||||
GetComposeId(ctx echo.Context, id string) error
|
||||
// status
|
||||
// (GET /status)
|
||||
GetStatus(ctx echo.Context) error
|
||||
}
|
||||
|
||||
// ServerInterfaceWrapper converts echo contexts to parameters.
|
||||
|
|
@ -103,6 +111,15 @@ func (w *ServerInterfaceWrapper) GetComposeId(ctx echo.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// GetStatus converts echo context to params.
|
||||
func (w *ServerInterfaceWrapper) GetStatus(ctx echo.Context) error {
|
||||
var err error
|
||||
|
||||
// Invoke the callback with all the unmarshalled arguments
|
||||
err = w.Handler.GetStatus(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// This is a simple interface which specifies echo.Route addition functions which
|
||||
// are present on both echo.Echo and echo.Group, since we want to allow using
|
||||
// either of them for path registration
|
||||
|
|
@ -127,5 +144,6 @@ func RegisterHandlers(router EchoRouter, si ServerInterface) {
|
|||
|
||||
router.POST("/compose", wrapper.PostCompose)
|
||||
router.GET("/compose/:id", wrapper.GetComposeId)
|
||||
router.GET("/status", wrapper.GetStatus)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,20 @@ info:
|
|||
name: Apache 2.0
|
||||
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
|
||||
paths:
|
||||
/status:
|
||||
get:
|
||||
summary: status
|
||||
tags: [ ]
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
headers: { }
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Status'
|
||||
operationId: GetStatus
|
||||
description: Simple status handler to check whether the service is up.
|
||||
'/compose/{id}':
|
||||
get:
|
||||
summary: The status of a compose
|
||||
|
|
@ -70,6 +84,14 @@ paths:
|
|||
type: string
|
||||
components:
|
||||
schemas:
|
||||
Status:
|
||||
required:
|
||||
- status
|
||||
properties:
|
||||
status:
|
||||
type: string
|
||||
enum:
|
||||
- OK
|
||||
ComposeStatus:
|
||||
required:
|
||||
- status
|
||||
|
|
|
|||
|
|
@ -247,6 +247,13 @@ func (h *apiHandlers) GetComposeId(ctx echo.Context, idstr string) error {
|
|||
return ctx.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
// GetStatus handles a /status GET request
|
||||
func (h *apiHandlers) GetStatus(ctx echo.Context) error {
|
||||
return ctx.JSON(http.StatusOK, &api.Status{
|
||||
Status: "OK",
|
||||
})
|
||||
}
|
||||
|
||||
// A simple echo.Binder(), which only accepts application/json, but is more
|
||||
// strict than echo's DefaultBinder. It does not handle binding query
|
||||
// parameters either.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue