/
responder.go
48 lines (41 loc) · 1.14 KB
/
responder.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
package api_impl
import (
"github.com/openziti/ziti/controller/api"
"github.com/openziti/ziti/controller/rest_model"
"github.com/openziti/foundation/v2/errorz"
"net/http"
)
func RespondWithCreatedId(responder api.Responder, id string, link rest_model.Link) {
createEnvelope := &rest_model.CreateEnvelope{
Data: &rest_model.CreateLocation{
Links: rest_model.Links{
"self": link,
},
ID: id,
},
Meta: &rest_model.Meta{},
}
responder.Respond(createEnvelope, http.StatusCreated)
}
func RespondWithOk(responder api.Responder, data interface{}, meta *rest_model.Meta) {
responder.Respond(&rest_model.Empty{
Data: data,
Meta: meta,
}, http.StatusOK)
}
type fabricResponseMapper struct{}
func (self fabricResponseMapper) EmptyOkData() interface{} {
return &rest_model.Empty{
Data: map[string]interface{}{},
Meta: &rest_model.Meta{},
}
}
func (self fabricResponseMapper) MapApiError(requestId string, apiError *errorz.ApiError) interface{} {
return &rest_model.APIErrorEnvelope{
Error: ToRestModel(apiError, requestId),
Meta: &rest_model.Meta{
APIEnrollmentVersion: ApiVersion,
APIVersion: ApiVersion,
},
}
}