@@ -14,13 +14,12 @@ import (
14
14
"github.com/go-chi/chi/v5"
15
15
)
16
16
17
- var tunnels map [string ]* cluster.Tunnel
17
+ // tunnels is a map of package names to tunnel objects used for storing connected tunnels
18
+ var tunnels map [string ]* cluster.Tunnel = make (map [string ]* cluster.Tunnel )
18
19
19
20
// ListTunnels lists all tunnel names
20
21
func ListTunnels (w http.ResponseWriter , _ * http.Request ) {
21
22
// make sure tunnels is initialized
22
- makeTunnels ()
23
-
24
23
// get the tunnel names
25
24
tunnelNames := make ([]string , 0 , len (tunnels ))
26
25
for name := range tunnels {
@@ -34,13 +33,10 @@ func ListTunnels(w http.ResponseWriter, _ *http.Request) {
34
33
func ConnectTunnel (w http.ResponseWriter , r * http.Request ) {
35
34
name := chi .URLParam (r , "name" )
36
35
37
- // make sure tunnels is initialized
38
- makeTunnels ()
39
-
40
36
// if the tunnel already exists, just launch the URL
41
37
if tunnels [name ] != nil {
42
38
launchTunnelURL (tunnels [name ], w , name )
43
- common .WriteJSONResponse (w , true , http .StatusCreated )
39
+ common .WriteJSONResponse (w , true , http .StatusOK )
44
40
return
45
41
}
46
42
@@ -60,7 +56,7 @@ func ConnectTunnel(w http.ResponseWriter, r *http.Request) {
60
56
tunnels [name ] = tunnel
61
57
launchTunnelURL (tunnel , w , name )
62
58
63
- common .WriteJSONResponse (w , true , http .StatusOK )
59
+ common .WriteJSONResponse (w , true , http .StatusCreated )
64
60
}
65
61
66
62
// DisconnectTunnel closes the tunnel for the requested resource
@@ -72,13 +68,6 @@ func DisconnectTunnel(w http.ResponseWriter, r *http.Request) {
72
68
common .WriteJSONResponse (w , true , http .StatusOK )
73
69
}
74
70
75
- // makeTunnels initializes the tunnels map if it is nil
76
- func makeTunnels () {
77
- if tunnels == nil {
78
- tunnels = make (map [string ]* cluster.Tunnel )
79
- }
80
- }
81
-
82
71
// launchTunnelURL launches the tunnel URL in the default browser
83
72
func launchTunnelURL (tunnel * cluster.Tunnel , w http.ResponseWriter , name string ) {
84
73
if err := exec .LaunchURL (tunnel .FullURL ()); err != nil {
0 commit comments