-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.go
70 lines (57 loc) · 1.69 KB
/
routes.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package headscale
import (
"context"
"net/http"
"time"
)
type RoutesResource struct {
Client HeadscaleClientInterface
}
type Route struct {
ID string `json:"id"`
Node NodeResponse `json:"node"`
Prefix string `json:"prefix"`
Advertised bool `json:"advertised"`
Enabled bool `json:"enabled"`
IsPrimary bool `json:"isPrimary"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt time.Time `json:"deletedAt"`
}
type RoutesResponse struct {
Routes []Route `json:"routes"`
}
func (r *RoutesResource) List(ctx context.Context) (RoutesResponse, error) {
var routes RoutesResponse
url := r.Client.buildURL("routes")
req, err := r.Client.buildRequest(ctx, http.MethodGet, url, requestOptions{})
if err != nil {
return routes, err
}
err = r.Client.do(ctx, req, &routes)
return routes, err
}
func (r *RoutesResource) Delete(ctx context.Context, id string) error {
url := r.Client.buildURL("routes", id)
req, err := r.Client.buildRequest(ctx, http.MethodDelete, url, requestOptions{})
if err != nil {
return err
}
return r.Client.do(ctx, req, nil)
}
func (r *RoutesResource) Disable(ctx context.Context, id string) error {
url := r.Client.buildURL("routes", id, "disable")
req, err := r.Client.buildRequest(ctx, http.MethodPost, url, requestOptions{})
if err != nil {
return err
}
return r.Client.do(ctx, req, nil)
}
func (r *RoutesResource) Enable(ctx context.Context, id string) error {
url := r.Client.buildURL("routes", id, "enable")
req, err := r.Client.buildRequest(ctx, http.MethodPost, url, requestOptions{})
if err != nil {
return err
}
return r.Client.do(ctx, req, nil)
}