-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.go
69 lines (54 loc) · 2.67 KB
/
spec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package chevron
import (
"context"
"net/http"
"github.com/efritz/response"
"github.com/go-nacelle/nacelle"
)
type (
// ResourceSpec represents the set of handlers (one for each HTTP method) to
// which a resource can respond.
ResourceSpec interface {
// Get is the handler invoked for the GET HTTP method.
Get(context.Context, *http.Request, nacelle.Logger) response.Response
// Options is the handler invoked for the OPTIONS HTTP method.
Options(context.Context, *http.Request, nacelle.Logger) response.Response
// Post is the handler invoked for the POST HTTP method.
Post(context.Context, *http.Request, nacelle.Logger) response.Response
// Put is the handler invoked for the PUT HTTP method.
Put(context.Context, *http.Request, nacelle.Logger) response.Response
// Patch is the handler invoked for the PATCH HTTP method.
Patch(context.Context, *http.Request, nacelle.Logger) response.Response
// Delete is the handler invoked for the DELETE HTTP method.
Delete(context.Context, *http.Request, nacelle.Logger) response.Response
}
// EmptySpec is a complete implementation of ResourceSpec that invokes the
// router's not implemented handler. A pointer to this struct should be the
// first embedded field in any resource - this allows a resource to simply
// "override" the handlers for methods relevant to a resource.
EmptySpec struct{}
)
// Get invokes the router's not implemented handler.
func (es *EmptySpec) Get(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response {
return GetNotImplementedHandler(ctx)(ctx, req, logger)
}
// Options invokes the router's not implemented handler.
func (es *EmptySpec) Options(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response {
return GetNotImplementedHandler(ctx)(ctx, req, logger)
}
// Post invokes the router's not implemented handler.
func (es *EmptySpec) Post(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response {
return GetNotImplementedHandler(ctx)(ctx, req, logger)
}
// Put invokes the router's not implemented handler.
func (es *EmptySpec) Put(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response {
return GetNotImplementedHandler(ctx)(ctx, req, logger)
}
// Patch invokes the router's not implemented handler.
func (es *EmptySpec) Patch(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response {
return GetNotImplementedHandler(ctx)(ctx, req, logger)
}
// Delete invokes the router's not implemented handler.
func (es *EmptySpec) Delete(ctx context.Context, req *http.Request, logger nacelle.Logger) response.Response {
return GetNotImplementedHandler(ctx)(ctx, req, logger)
}