-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
http.go
40 lines (36 loc) · 1.6 KB
/
http.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
package coapconv
import (
"net/http"
coapCodes "github.com/plgd-dev/go-coap/v3/message/codes"
)
var coapToHTTP = map[coapCodes.Code]int{
coapCodes.Created: http.StatusCreated,
coapCodes.Deleted: http.StatusOK,
coapCodes.Valid: http.StatusAccepted,
coapCodes.Changed: http.StatusOK,
coapCodes.Content: http.StatusOK,
coapCodes.Continue: http.StatusContinue,
coapCodes.BadRequest: http.StatusBadRequest,
coapCodes.Unauthorized: http.StatusUnauthorized,
coapCodes.BadOption: http.StatusBadRequest,
coapCodes.Forbidden: http.StatusForbidden,
coapCodes.NotFound: http.StatusNotFound,
coapCodes.MethodNotAllowed: http.StatusMethodNotAllowed,
coapCodes.NotAcceptable: http.StatusNotAcceptable,
coapCodes.RequestEntityIncomplete: http.StatusBadRequest,
coapCodes.PreconditionFailed: http.StatusPreconditionFailed,
coapCodes.RequestEntityTooLarge: http.StatusRequestEntityTooLarge,
coapCodes.UnsupportedMediaType: http.StatusUnsupportedMediaType,
coapCodes.InternalServerError: http.StatusInternalServerError,
coapCodes.NotImplemented: http.StatusNotImplemented,
coapCodes.BadGateway: http.StatusBadGateway,
coapCodes.ServiceUnavailable: http.StatusServiceUnavailable,
coapCodes.GatewayTimeout: http.StatusGatewayTimeout,
}
// ToHTTPCode converts coap.Code to http.Status
func ToHTTPCode(code coapCodes.Code, def int) int {
if val, ok := coapToHTTP[code]; ok {
return val
}
return def
}