forked from kevana/ui-for-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdockerui.go
41 lines (33 loc) · 843 Bytes
/
dockerui.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"flag"
"log"
"net/http"
"net/http/httputil"
"net/url"
)
var (
endpoint = flag.String("e", "", "Dockerd endpoint")
addr = flag.String("p", ":9000", "Address and port to serve dockerui")
assets = flag.String("a", ".", "Path to the assets")
)
func createHandler(dir string, dockerEndpoint string) http.Handler {
mux := http.NewServeMux()
fileHandler := http.FileServer(http.Dir(dir))
u, err := url.Parse(dockerEndpoint)
if err != nil {
log.Fatal(err)
return nil
}
reverseProxy := httputil.NewSingleHostReverseProxy(u)
mux.Handle("/dockerapi/", http.StripPrefix("/dockerapi", reverseProxy))
mux.Handle("/", fileHandler)
return mux
}
func main() {
flag.Parse()
handler := createHandler(*assets, *endpoint)
if err := http.ListenAndServe(*addr, handler); err != nil {
log.Fatal(err)
}
}