Skip to content

Commit

Permalink
feat: better list output when no services connected
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan committed Oct 29, 2021
1 parent ee483b7 commit ba082f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 1 addition & 4 deletions logged_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ func (lh *LoggedHandler) RemoveVhost(host string) {

// DumpServers to the given writer
func (lh *LoggedHandler) DumpServers(w io.Writer) {
fmt.Fprintf(w, "%d vhosts:\n", len(lh.vhostMux.Servers))
for _, v := range lh.vhostMux.Servers {
fmt.Fprintf(w, "%s -> %s:%d\n", v.Host, v.ServiceHost, v.Port)
}
lh.vhostMux.DumpServers(w)
}

// Create multi-certificate TLS config from vhost config
Expand Down
16 changes: 16 additions & 0 deletions vhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package vproxy

import (
"fmt"
"io"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -53,6 +54,21 @@ func (v *VhostMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
vhost.Handler.ServeHTTP(w, r)
}

// DumpServers to the given writer
func (v *VhostMux) DumpServers(w io.Writer) {
switch c := len(v.Servers); c {
case 0:
fmt.Fprintln(w, "0 vhosts")
case 1:
fmt.Fprintln(w, "1 vhost:")
default:
fmt.Fprintf(w, "%d vhosts:", c)
}
for _, v := range v.Servers {
fmt.Fprintf(w, "%s -> %s:%d\n", v.Host, v.ServiceHost, v.Port)
}
}

// CreateVhostMux config, optionally initialized with a list of bindings
func CreateVhostMux(bindings []string, useTLS bool) *VhostMux {
servers := make(map[string]*Vhost)
Expand Down

0 comments on commit ba082f6

Please sign in to comment.