/
client.go
46 lines (38 loc) · 1.06 KB
/
client.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
package device
import (
"net/url"
"github.com/go-kit/kit/endpoint"
"github.com/go-kit/kit/log"
httptransport "github.com/go-kit/kit/transport/http"
"github.com/micromdm/micromdm/pkg/httputil"
)
func NewHTTPClient(instance, token string, logger log.Logger, opts ...httptransport.ClientOption) (Service, error) {
u, err := url.Parse(instance)
if err != nil {
return nil, err
}
var listDevicesEndpoint endpoint.Endpoint
{
listDevicesEndpoint = httptransport.NewClient(
"POST",
httputil.CopyURL(u, "/v1/devices"),
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
decodeListDevicesResponse,
opts...,
).Endpoint()
}
var removeDevicesEndpoint endpoint.Endpoint
{
removeDevicesEndpoint = httptransport.NewClient(
"DELETE",
httputil.CopyURL(u, "/v1/devices"),
httputil.EncodeRequestWithToken(token, httptransport.EncodeJSONRequest),
decodeRemoveDevicesResponse,
opts...,
).Endpoint()
}
return Endpoints{
ListDevicesEndpoint: listDevicesEndpoint,
RemoveDevicesEndpoint: removeDevicesEndpoint,
}, nil
}