Implement tunnel delete
This commit is contained in:
parent
98a049b2e6
commit
c55b7283ec
1 changed files with 17 additions and 0 deletions
|
@ -58,6 +58,8 @@ func (p *BoringProxy) handleAdminRequest(w http.ResponseWriter, r *http.Request)
|
|||
func (p *BoringProxy) handleTunnels(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("handleTunnels")
|
||||
|
||||
query := r.URL.Query()
|
||||
|
||||
if r.Method == "GET" {
|
||||
body, err := json.Marshal(p.tunMan.tunnels)
|
||||
if err != nil {
|
||||
|
@ -68,6 +70,15 @@ func (p *BoringProxy) handleTunnels(w http.ResponseWriter, r *http.Request) {
|
|||
w.Write([]byte(body))
|
||||
} else if r.Method == "POST" {
|
||||
p.handleCreateTunnel(w, r)
|
||||
} else if r.Method == "DELETE" {
|
||||
if len(query["host"]) != 1 {
|
||||
w.WriteHeader(400)
|
||||
w.Write([]byte("Invalid host parameter"))
|
||||
return
|
||||
}
|
||||
host := query["host"][0]
|
||||
|
||||
p.tunMan.DeleteTunnel(host)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,6 +209,12 @@ func (m *TunnelManager) SetTunnel(host string, port int) {
|
|||
m.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (m *TunnelManager) DeleteTunnel(host string) {
|
||||
m.mutex.Lock()
|
||||
delete(m.tunnels, host)
|
||||
m.mutex.Unlock()
|
||||
}
|
||||
|
||||
func (m *TunnelManager) GetPort(serverName string) (int, error) {
|
||||
m.mutex.Lock()
|
||||
port, exists := m.tunnels[serverName]
|
||||
|
|
Loading…
Reference in a new issue