-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource.go
79 lines (69 loc) · 2.15 KB
/
resource.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
70
71
72
73
74
75
76
77
78
79
package resozyme
import (
"context"
"net/http"
)
// Resource represents a resource.
type Resource interface {
// Href returns the pathinfo.
Href() string
// Context returns the context.
Context() context.Context
// Code returns the status code.
Code() int
// Header returns the HTTP header object.
Header() http.Header
// View returns the view part.
View() interface{}
// Error returns an error if occurred.
Error() error
// SetCode sets the code.
SetCode(code int)
// SetError sets an error.
SetError(error error)
// AddLink adds a link.
AddLink(rel string, l Link)
// AddLinkCollection adds the link collection.
AddLinkCollection(rel string, l []Link)
// LinkResource adds a link to the resource.
LinkResource(rel string, aResc Resource)
// LinkResourceCollection adds link to the resource collection.
LinkResourceCollection(rel string, aResc []Resource)
// Links returns the links.
Links() map[string]Link
// LinksCollection returns link collection.
LinksCollection() map[string][]Link
// Embed embeds a resource.
Embed(rel string, er Resource)
// Embed embeds the resource collection.
EmbedCollection(rel string, er []Resource)
// Embedded returns embedded resources.
Embedded() map[string]Resource
// EmbeddedCollection returns embedded the resource collection.
EmbeddedCollection() map[string][]Resource
// Renderer returns the renderer.
Renderer() Renderer
// SetRenderer sets a renderer to the resource.
SetRenderer(renderer Renderer)
// Bind binds passed value to the resource.
Bind(i interface{})
// OnGet handles the GET request.
OnGet(w http.ResponseWriter, r *http.Request)
// OnGet handles the POST request.
OnPost(w http.ResponseWriter, r *http.Request)
// OnGet handles the PUT request.
OnPut(w http.ResponseWriter, r *http.Request)
// OnGet handles the PATCH request.
OnPatch(w http.ResponseWriter, r *http.Request)
// OnGet handles the DELETE request.
OnDelete(w http.ResponseWriter, r *http.Request)
}
// Renderer provides a resource renderer interface.
type Renderer interface {
// Render renders a resource view.
Render(resc Resource, pretty bool) []byte
}
// Link represents a link.
type Link struct {
Href string
}