forked from zubairhamed/betwixt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
154 lines (117 loc) · 3.41 KB
/
response.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Various responses to a LWM2M Server request
// Typically responses represent a CoAP Request code
package betwixt
import (
"github.com/zubairhamed/canopus"
)
// Created creates a LWM2M Response (CreatedResponse) with CoAP code 201 - Created
func Created() Lwm2mResponse {
return &CreatedResponse{}
}
type CreatedResponse struct {
}
func (r *CreatedResponse) GetResponseCode() canopus.CoapCode {
return canopus.CoapCodeCreated
}
func (r *CreatedResponse) GetResponseValue() Value {
return Empty()
}
// Deleted creates a LWM2M Response (DeletedResponse) with CoAP code 202 - Deleted
func Deleted() Lwm2mResponse {
return &DeletedResponse{}
}
type DeletedResponse struct {
}
func (r *DeletedResponse) GetResponseCode() canopus.CoapCode {
return canopus.CoapCodeDeleted
}
func (r *DeletedResponse) GetResponseValue() Value {
return Empty()
}
// Changed creates a LWM2M Response (ChangedResponse) with CoAP code 204 - Changed
func Changed() Lwm2mResponse {
return &ChangedResponse{}
}
type ChangedResponse struct {
}
func (r *ChangedResponse) GetResponseCode() canopus.CoapCode {
return canopus.CoapCodeChanged
}
func (r *ChangedResponse) GetResponseValue() Value {
return Empty()
}
// Content creates a LWM2M Response (ContentResponse) with CoAP code 205 - Content
func Content(val Value) Lwm2mResponse {
return &ContentResponse{
val: val,
}
}
type ContentResponse struct {
val Value
}
func (r *ContentResponse) GetResponseCode() canopus.CoapCode {
return canopus.CoapCodeContent
}
func (r *ContentResponse) GetResponseValue() Value {
return r.val
}
// BadRequest creates a LWM2M Response (BadRequestResponse) with CoAP code 400 - Bad Request
func BadRequest() Lwm2mResponse {
return &BadRequestResponse{}
}
type BadRequestResponse struct {
}
func (r *BadRequestResponse) GetResponseCode() canopus.CoapCode {
return canopus.CoapCodeBadRequest
}
func (r *BadRequestResponse) GetResponseValue() Value {
return Empty()
}
// Unauthorized creates a LWM2M Response (UnauthorizedResponse) with CoAP code 401 - Unauthorized
func Unauthorized() Lwm2mResponse {
return &UnauthorizedResponse{}
}
type UnauthorizedResponse struct {
}
func (r *UnauthorizedResponse) GetResponseCode() canopus.CoapCode {
return canopus.CoapCodeUnauthorized
}
func (r *UnauthorizedResponse) GetResponseValue() Value {
return Empty()
}
// NotFound creates a LWM2M Response (NotFoundResponse) with CoAP code 404 - Not Found
func NotFound() Lwm2mResponse {
return &NotFoundResponse{}
}
type NotFoundResponse struct {
}
func (r *NotFoundResponse) GetResponseCode() canopus.CoapCode {
return canopus.CoapCodeNotFound
}
func (r *NotFoundResponse) GetResponseValue() Value {
return Empty()
}
/// MethodNotAllowed creates a LWM2M Response (MethodNotAllowedResponse) with CoAP code 405 - Method Not Allowed
func MethodNotAllowed() Lwm2mResponse {
return &MethodNotAllowedResponse{}
}
type MethodNotAllowedResponse struct {
}
func (r *MethodNotAllowedResponse) GetResponseCode() canopus.CoapCode {
return canopus.CoapCodeMethodNotAllowed
}
func (r *MethodNotAllowedResponse) GetResponseValue() Value {
return Empty()
}
// Conflict creates a LWM2M Response (ConflictResponse) with CoAP code 409 - Conflict
func Conflict() Lwm2mResponse {
return &ConflictResponse{}
}
type ConflictResponse struct {
}
func (r *ConflictResponse) GetResponseCode() canopus.CoapCode {
return canopus.CoapCodeConflict
}
func (r *ConflictResponse) GetResponseValue() Value {
return Empty()
}