@@ -20,15 +20,20 @@ import (
2020
2121var (
2222 cli * client.Client
23- addr = flag .String ("addr" , ":8080" , "http service address" )
24- base = flag .String ("base" , "/" , "base address of the application to mount" )
23+ addr = ""
24+ ssl = false
25+ base = "/"
2526 upgrader = websocket.Upgrader {}
2627 version = "dev"
2728 commit = "none"
2829 date = "unknown"
2930)
3031
3132func init () {
33+ flag .StringVar (& addr , "addr" , ":8080" , "http service address" )
34+ flag .StringVar (& base , "base" , "/" , "base address of the application to mount" )
35+ flag .BoolVarP (& ssl , "ssl" , "s" , false , "Uses websockets over ssl if enabled" )
36+
3237 var err error
3338 cli , err = client .NewClientWithOpts (client .FromEnv )
3439 if err != nil {
@@ -40,19 +45,19 @@ func init() {
4045func main () {
4146 r := mux .NewRouter ()
4247
43- if * base != "/" {
44- r .HandleFunc (* base , http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
45- http .Redirect (w , req , * base + "/" , http .StatusMovedPermanently )
48+ if base != "/" {
49+ r .HandleFunc (base , http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
50+ http .Redirect (w , req , base + "/" , http .StatusMovedPermanently )
4651 }))
4752 }
4853
49- s := r .PathPrefix (* base ).Subrouter ()
54+ s := r .PathPrefix (base ).Subrouter ()
5055 box := packr .NewBox ("./static" )
5156
5257 s .HandleFunc ("/api/containers.json" , listContainers )
5358 s .HandleFunc ("/api/logs" , logs )
5459 s .HandleFunc ("/version" , versionHandler )
55- s .PathPrefix ("/" ).Handler (http .StripPrefix (* base , http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
60+ s .PathPrefix ("/" ).Handler (http .StripPrefix (base , http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
5661 fileServer := http .FileServer (box )
5762 if box .Has (req .URL .Path ) && req .URL .Path != "" && req .URL .Path != "/" {
5863 fileServer .ServeHTTP (w , req )
@@ -61,7 +66,7 @@ func main() {
6166 }
6267 })))
6368
64- log .Fatal (http .ListenAndServe (* addr , r ))
69+ log .Fatal (http .ListenAndServe (addr , r ))
6570}
6671
6772func versionHandler (w http.ResponseWriter , r * http.Request ) {
@@ -87,10 +92,13 @@ func handleIndex(box packr.Box, w http.ResponseWriter) {
8792 }
8893
8994 path := ""
90- if * base != "/" {
91- path = * base
95+ if base != "/" {
96+ path = base
9297 }
93- data := struct { Base string }{Base : path }
98+ data := struct {
99+ Base string
100+ SSL bool
101+ }{path , ssl }
94102 err = tmpl .Execute (w , data )
95103 if err != nil {
96104 panic (err )
0 commit comments