mirror of
https://github.com/openziti/ziti.git
synced 2026-09-10 08:45:41 +00:00
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package api_impl
|
|
|
|
import (
|
|
"github.com/openziti/fabric/controller/api"
|
|
"github.com/openziti/fabric/rest_model"
|
|
"github.com/openziti/foundation/util/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,
|
|
},
|
|
}
|
|
}
|