mirror of
https://github.com/micromdm/micromdm/
synced 2026-08-12 13:25:38 +08:00
38 lines
819 B
Go
38 lines
819 B
Go
package push
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/go-kit/kit/endpoint"
|
|
)
|
|
|
|
var errEmptyRequest = errors.New("request must contain UDID of the device")
|
|
|
|
type Endpoints struct {
|
|
PushEndpoint endpoint.Endpoint
|
|
}
|
|
|
|
type pushRequest struct {
|
|
UDID string
|
|
}
|
|
|
|
type pushResponse struct {
|
|
Status string `json:"status,omitempty"`
|
|
ID string `json:"push_notification_id,omitempty"`
|
|
Err error `json:"error,omitempty"`
|
|
}
|
|
|
|
func (r pushResponse) error() error { return r.Err }
|
|
|
|
func MakePushEndpoint(svc Service) endpoint.Endpoint {
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
req := request.(pushRequest)
|
|
id, err := svc.Push(ctx, req.UDID)
|
|
if err != nil {
|
|
return pushResponse{Err: err, Status: "failure"}, nil
|
|
}
|
|
return pushResponse{Status: "success", ID: id}, nil
|
|
}
|
|
}
|