Skip to content

Commit 4997edb

Browse files
committedJun 3, 2016
feat(pkg): add ping endpoint
1 parent 20cdeae commit 4997edb

File tree

6 files changed

+143
-1
lines changed

6 files changed

+143
-1
lines changed
 

‎pkg/handlers/ping.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package handlers
2+
3+
import (
4+
"github.com/deis/workflow-manager-api/pkg/swagger/restapi/operations"
5+
"github.com/go-swagger/go-swagger/httpkit/middleware"
6+
)
7+
8+
// Ping is the handler for the ping endpoint
9+
func Ping() middleware.Responder {
10+
return operations.NewPingOK()
11+
}

‎pkg/swagger/restapi/configure_workflow_manager.go

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ func configureAPI(api *operations.WorkflowManagerAPI) http.Handler {
8686
return handlers.PublishVersion(params, rdsDB)
8787
})
8888

89+
api.PingHandler = operations.PingHandlerFunc(func() middleware.Responder {
90+
return handlers.Ping()
91+
})
92+
8993
api.ServerShutdown = func() {}
9094

9195
return setupGlobalMiddleware(api.Serve(setupMiddlewares))

‎pkg/swagger/restapi/embedded_spec.go

+1-1
Large diffs are not rendered by default.
+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package operations
2+
3+
// This file was generated by the swagger tool.
4+
// Editing this file might prove futile when you re-run the generate command
5+
6+
import (
7+
"net/http"
8+
9+
middleware "github.com/go-swagger/go-swagger/httpkit/middleware"
10+
)
11+
12+
// PingHandlerFunc turns a function with the right signature into a ping handler
13+
type PingHandlerFunc func() middleware.Responder
14+
15+
// Handle executing the request and returning a response
16+
func (fn PingHandlerFunc) Handle() middleware.Responder {
17+
return fn()
18+
}
19+
20+
// PingHandler interface for that can handle valid ping params
21+
type PingHandler interface {
22+
Handle() middleware.Responder
23+
}
24+
25+
// NewPing creates a new http.Handler for the ping operation
26+
func NewPing(ctx *middleware.Context, handler PingHandler) *Ping {
27+
return &Ping{Context: ctx, Handler: handler}
28+
}
29+
30+
/*Ping swagger:route GET /ping ping
31+
32+
ping the versions API server
33+
34+
*/
35+
type Ping struct {
36+
Context *middleware.Context
37+
Handler PingHandler
38+
}
39+
40+
func (o *Ping) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
41+
route, _ := o.Context.RouteInfo(r)
42+
43+
if err := o.Context.BindValidRequest(r, route, nil); err != nil { // bind params
44+
o.Context.Respond(rw, r, route.Produces, route, err)
45+
return
46+
}
47+
48+
res := o.Handler.Handle() // actually handle the request
49+
50+
o.Context.Respond(rw, r, route.Produces, route, res)
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package operations
2+
3+
// This file was generated by the swagger tool.
4+
// Editing this file might prove futile when you re-run the swagger generate command
5+
6+
import (
7+
"net/http"
8+
9+
"github.com/go-swagger/go-swagger/httpkit"
10+
)
11+
12+
/*PingOK server ping success
13+
14+
swagger:response pingOK
15+
*/
16+
type PingOK struct {
17+
}
18+
19+
// NewPingOK creates PingOK with default headers values
20+
func NewPingOK() *PingOK {
21+
return &PingOK{}
22+
}
23+
24+
// WriteResponse to the client
25+
func (o *PingOK) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {
26+
27+
rw.WriteHeader(200)
28+
}
29+
30+
/*PingDefault unexpected error
31+
32+
swagger:response pingDefault
33+
*/
34+
type PingDefault struct {
35+
_statusCode int
36+
}
37+
38+
// NewPingDefault creates PingDefault with default headers values
39+
func NewPingDefault(code int) *PingDefault {
40+
if code <= 0 {
41+
code = 500
42+
}
43+
44+
return &PingDefault{
45+
_statusCode: code,
46+
}
47+
}
48+
49+
// WithStatusCode adds the status to the ping default response
50+
func (o *PingDefault) WithStatusCode(code int) *PingDefault {
51+
o._statusCode = code
52+
return o
53+
}
54+
55+
// SetStatusCode sets the status to the ping default response
56+
func (o *PingDefault) SetStatusCode(code int) {
57+
o._statusCode = code
58+
}
59+
60+
// WriteResponse to the client
61+
func (o *PingDefault) WriteResponse(rw http.ResponseWriter, producer httpkit.Producer) {
62+
63+
rw.WriteHeader(o._statusCode)
64+
}

‎pkg/swagger/restapi/operations/workflow_manager_api.go

+11
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ type WorkflowManagerAPI struct {
6161
GetComponentsByLatestReleaseHandler GetComponentsByLatestReleaseHandler
6262
// GetComponentsByLatestReleaseForV2Handler sets the operation handler for the get components by latest release for v2 operation
6363
GetComponentsByLatestReleaseForV2Handler GetComponentsByLatestReleaseForV2Handler
64+
// PingHandler sets the operation handler for the ping operation
65+
PingHandler PingHandler
6466
// PublishComponentReleaseHandler sets the operation handler for the publish component release operation
6567
PublishComponentReleaseHandler PublishComponentReleaseHandler
6668

@@ -154,6 +156,10 @@ func (o *WorkflowManagerAPI) Validate() error {
154156
unregistered = append(unregistered, "GetComponentsByLatestReleaseForV2Handler")
155157
}
156158

159+
if o.PingHandler == nil {
160+
unregistered = append(unregistered, "PingHandler")
161+
}
162+
157163
if o.PublishComponentReleaseHandler == nil {
158164
unregistered = append(unregistered, "PublishComponentReleaseHandler")
159165
}
@@ -276,6 +282,11 @@ func (o *WorkflowManagerAPI) initHandlerCache() {
276282
}
277283
o.handlers["POST"]["/v2/versions/latest"] = NewGetComponentsByLatestReleaseForV2(o.context, o.GetComponentsByLatestReleaseForV2Handler)
278284

285+
if o.handlers["GET"] == nil {
286+
o.handlers[strings.ToUpper("GET")] = make(map[string]http.Handler)
287+
}
288+
o.handlers["GET"]["/ping"] = NewPing(o.context, o.PingHandler)
289+
279290
if o.handlers["POST"] == nil {
280291
o.handlers[strings.ToUpper("POST")] = make(map[string]http.Handler)
281292
}

0 commit comments

Comments
 (0)
Please sign in to comment.