/
server.go
40 lines (33 loc) · 1.17 KB
/
server.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 device
import (
"github.com/go-kit/kit/endpoint"
httptransport "github.com/go-kit/kit/transport/http"
"github.com/gorilla/mux"
"github.com/micromdm/micromdm/pkg/httputil"
)
type Endpoints struct {
ListDevicesEndpoint endpoint.Endpoint
RemoveDevicesEndpoint endpoint.Endpoint
}
func MakeServerEndpoints(s Service, outer endpoint.Middleware, others ...endpoint.Middleware) Endpoints {
return Endpoints{
ListDevicesEndpoint: endpoint.Chain(outer, others...)(MakeListDevicesEndpoint(s)),
RemoveDevicesEndpoint: endpoint.Chain(outer, others...)(MakeRemoveDevicesEndpoint(s)),
}
}
func RegisterHTTPHandlers(r *mux.Router, e Endpoints, options ...httptransport.ServerOption) {
// POST /v1/devices get a list of devices managed by the server
// DELETE /v1/devices remove one or more devices from the server
r.Methods("POST").Path("/v1/devices").Handler(httptransport.NewServer(
e.ListDevicesEndpoint,
decodeListDevicesRequest,
httputil.EncodeJSONResponse,
options...,
))
r.Methods("DELETE").Path("/v1/devices").Handler(httptransport.NewServer(
e.RemoveDevicesEndpoint,
decodeRemoveDevicesRequest,
httputil.EncodeJSONResponse,
options...,
))
}