File tree Expand file tree Collapse file tree 4 files changed +27
-9
lines changed Expand file tree Collapse file tree 4 files changed +27
-9
lines changed Original file line number Diff line number Diff line change 5
5
"net/http"
6
6
7
7
"github.com/code-ready/admin-helper/pkg/api"
8
- "github.com/code-ready/admin-helper/pkg/hosts"
9
8
"github.com/kardianos/service"
10
9
"github.com/spf13/cobra"
11
10
)
@@ -80,12 +79,7 @@ func (p *program) Start(s service.Service) error {
80
79
_ = logger .Error (err )
81
80
return
82
81
}
83
- hosts , err := hosts .New ()
84
- if err != nil {
85
- _ = logger .Error (err )
86
- return
87
- }
88
- if err := http .Serve (ln , api .Mux (hosts )); err != nil {
82
+ if err := http .Serve (ln , api .Mux ()); err != nil {
89
83
_ = logger .Error (err )
90
84
return
91
85
}
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import (
10
10
"github.com/code-ready/admin-helper/pkg/types"
11
11
)
12
12
13
- func Mux (hosts * hosts. Hosts ) http.Handler {
13
+ func Mux () http.Handler {
14
14
mux := http .NewServeMux ()
15
15
mux .HandleFunc ("/version" , func (w http.ResponseWriter , r * http.Request ) {
16
16
_ , _ = fmt .Fprint (w , constants .Version )
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import (
11
11
)
12
12
13
13
func TestMux (t * testing.T ) {
14
- ts := httptest .NewServer (Mux (nil ))
14
+ ts := httptest .NewServer (Mux ())
15
15
defer ts .Close ()
16
16
17
17
client := client .New (http .DefaultClient , ts .URL )
Original file line number Diff line number Diff line change @@ -43,6 +43,14 @@ func defaultFilter(s string) bool {
43
43
return clusterRegexp .MatchString (s ) || appRegexp .MatchString (s )
44
44
}
45
45
46
+ func Add (ip string , hosts []string ) error {
47
+ h , err := New ()
48
+ if err != nil {
49
+ return err
50
+ }
51
+ return h .Add (ip , hosts )
52
+ }
53
+
46
54
func (h * Hosts ) Add (ip string , hosts []string ) error {
47
55
if err := h .verifyHosts (hosts ); err != nil {
48
56
return err
@@ -75,6 +83,14 @@ func (h *Hosts) Add(ip string, hosts []string) error {
75
83
return h .File .Flush ()
76
84
}
77
85
86
+ func Remove (hosts []string ) error {
87
+ h , err := New ()
88
+ if err != nil {
89
+ return err
90
+ }
91
+ return h .Remove (hosts )
92
+ }
93
+
78
94
func (h * Hosts ) Remove (hosts []string ) error {
79
95
if err := h .verifyHosts (hosts ); err != nil {
80
96
return err
@@ -102,6 +118,14 @@ func (h *Hosts) Remove(hosts []string) error {
102
118
return h .File .Flush ()
103
119
}
104
120
121
+ func Clean (rawSuffixes []string ) error {
122
+ h , err := New ()
123
+ if err != nil {
124
+ return err
125
+ }
126
+ return h .Clean (rawSuffixes )
127
+ }
128
+
105
129
func (h * Hosts ) Clean (rawSuffixes []string ) error {
106
130
if err := h .checkIsWritable (); err != nil {
107
131
return err
You can’t perform that action at this time.
0 commit comments