Skip to content

Commit

Permalink
support for MPD_HOST
Browse files Browse the repository at this point in the history
  • Loading branch information
alicebob committed Feb 8, 2018
1 parent 532faf0 commit 9d295bf
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions siren/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
)

var (
version = "master"
mpdURL = flag.String("mpd", "localhost:6600", "mpd URL")
listen = flag.String("listen", ":6601", "http listen")
static = flag.String("docroot", "", "use dir as docroot. Uses build-in files if empty")
showVersion = flag.Bool("version", false, "show version")
mpdURL = flag.String("mpd", "localhost:6600", "MPD address. Uses MPD_HOST by default, port optional")
listen = flag.String("listen", ":6601", "http listen address")
static = flag.String("docroot", "", "for development: use directory as docroot, not the build-in files")
showVersion = flag.Bool("version", false, "show version and exit")
)

func main() {
Expand All @@ -24,7 +25,8 @@ func main() {
os.Exit(0)
}

c, err := NewMPD(*mpdURL)
u := url(*mpdURL)
c, err := NewMPD(u)
if err != nil {
log.Fatal(err)
}
Expand All @@ -35,7 +37,8 @@ func main() {
} else {
fs = FS(false)
}
log.Printf("listening on %s...\n", *listen)
log.Printf("MPD used: %s\n", u)
log.Printf("listening on: %s\n", *listen)
log.Fatal(http.ListenAndServe(*listen, mux(c, fs)))
}

Expand All @@ -45,3 +48,13 @@ func mux(c *MPD, root http.FileSystem) *http.ServeMux {
r.Handle("/", http.FileServer(root))
return r
}

func url(u string) string {
if h, _ := os.LookupEnv("MPD_HOST"); h != "" {
u = h
}
if _, _, err := net.SplitHostPort(u); err != nil {
u = u + ":6600"
}
return u
}

0 comments on commit 9d295bf

Please sign in to comment.