Skip to content

Commit

Permalink
feat(pkg): add ping endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
arschles committed Jun 3, 2016
1 parent 20cdeae commit 4997edb
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 1 deletion.
11 changes: 11 additions & 0 deletions pkg/handlers/ping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package handlers

import (
"github.com/deis/workflow-manager-api/pkg/swagger/restapi/operations"
"github.com/go-swagger/go-swagger/httpkit/middleware"
)

// Ping is the handler for the ping endpoint
func Ping() middleware.Responder {
return operations.NewPingOK()
}
4 changes: 4 additions & 0 deletions pkg/swagger/restapi/configure_workflow_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func configureAPI(api *operations.WorkflowManagerAPI) http.Handler {
return handlers.PublishVersion(params, rdsDB)
})

api.PingHandler = operations.PingHandlerFunc(func() middleware.Responder {
return handlers.Ping()
})

api.ServerShutdown = func() {}

return setupGlobalMiddleware(api.Serve(setupMiddlewares))
Expand Down
2 changes: 1 addition & 1 deletion pkg/swagger/restapi/embedded_spec.go

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions pkg/swagger/restapi/operations/ping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package operations

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command

import (
"net/http"

middleware "github.com/go-swagger/go-swagger/httpkit/middleware"
)

// PingHandlerFunc turns a function with the right signature into a ping handler
type PingHandlerFunc func() middleware.Responder

// Handle executing the request and returning a response
func (fn PingHandlerFunc) Handle() middleware.Responder {
return fn()
}

// PingHandler interface for that can handle valid ping params
type PingHandler interface {
Handle() middleware.Responder
}

// NewPing creates a new http.Handler for the ping operation
func NewPing(ctx *middleware.Context, handler PingHandler) *Ping {
return &Ping{Context: ctx, Handler: handler}
}

/*Ping swagger:route GET /ping ping
ping the versions API server
*/
type Ping struct {
Context *middleware.Context
Handler PingHandler
}

func (o *Ping) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, _ := o.Context.RouteInfo(r)

if err := o.Context.BindValidRequest(r, route, nil); err != nil { // bind params
o.Context.Respond(rw, r, route.Produces, route, err)
return
}

res := o.Handler.Handle() // actually handle the request

o.Context.Respond(rw, r, route.Produces, route, res)

}
64 changes: 64 additions & 0 deletions pkg/swagger/restapi/operations/ping_responses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package operations

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
"net/http"

"github.com/go-swagger/go-swagger/httpkit"
)

/*PingOK server ping success
swagger:response pingOK
*/
type PingOK struct {
}

// NewPingOK creates PingOK with default headers values
func NewPingOK() *PingOK {
return &PingOK{}
}

// WriteResponse to the client
func (o *PingOK) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {

rw.WriteHeader(200)
}

/*PingDefault unexpected error
swagger:response pingDefault
*/
type PingDefault struct {
_statusCode int
}

// NewPingDefault creates PingDefault with default headers values
func NewPingDefault(code int) *PingDefault {
if code <= 0 {
code = 500
}

return &PingDefault{
_statusCode: code,
}
}

// WithStatusCode adds the status to the ping default response
func (o *PingDefault) WithStatusCode(code int) *PingDefault {
o._statusCode = code
return o
}

// SetStatusCode sets the status to the ping default response
func (o *PingDefault) SetStatusCode(code int) {
o._statusCode = code
}

// WriteResponse to the client
func (o *PingDefault) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {

rw.WriteHeader(o._statusCode)
}
11 changes: 11 additions & 0 deletions pkg/swagger/restapi/operations/workflow_manager_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type WorkflowManagerAPI struct {
GetComponentsByLatestReleaseHandler GetComponentsByLatestReleaseHandler
// GetComponentsByLatestReleaseForV2Handler sets the operation handler for the get components by latest release for v2 operation
GetComponentsByLatestReleaseForV2Handler GetComponentsByLatestReleaseForV2Handler
// PingHandler sets the operation handler for the ping operation
PingHandler PingHandler
// PublishComponentReleaseHandler sets the operation handler for the publish component release operation
PublishComponentReleaseHandler PublishComponentReleaseHandler

Expand Down Expand Up @@ -154,6 +156,10 @@ func (o *WorkflowManagerAPI) Validate() error {
unregistered = append(unregistered, "GetComponentsByLatestReleaseForV2Handler")
}

if o.PingHandler == nil {
unregistered = append(unregistered, "PingHandler")
}

if o.PublishComponentReleaseHandler == nil {
unregistered = append(unregistered, "PublishComponentReleaseHandler")
}
Expand Down Expand Up @@ -276,6 +282,11 @@ func (o *WorkflowManagerAPI) initHandlerCache() {
}
o.handlers["POST"]["/v2/versions/latest"] = NewGetComponentsByLatestReleaseForV2(o.context, o.GetComponentsByLatestReleaseForV2Handler)

if o.handlers["GET"] == nil {
o.handlers[strings.ToUpper("GET")] = make(map[string]http.Handler)
}
o.handlers["GET"]["/ping"] = NewPing(o.context, o.PingHandler)

if o.handlers["POST"] == nil {
o.handlers[strings.ToUpper("POST")] = make(map[string]http.Handler)
}
Expand Down

0 comments on commit 4997edb

Please sign in to comment.