From ada6290a1a67a5be053b912213001006cf048ef6 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Wed, 7 Oct 2020 19:23:17 +0300 Subject: [PATCH] Introduce address flag This can be useful in https://github.com/cirruslabs/cirrus-cli/pull/121 where listening 0.0.0.0 will make the proxy reachable from other containers that want to use the cache. --- cmd/main.go | 4 +++- proxy/http_proxy.go | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 3dfa6b7..de487ca 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -9,6 +9,8 @@ import ( ) func main() { + var address string + flag.StringVar(&address, "address", "127.0.0.1", "Address to listen on") var port int64 flag.Int64Var(&port, "port", 8080, "Port to serve") var bucketName string @@ -29,7 +31,7 @@ func main() { bucketHandler := client.Bucket(bucketName) storageProxy := http_cache.NewStorageProxy(bucketHandler, defaultPrefix) - err = storageProxy.Serve(port) + err = storageProxy.Serve(address, port) if err != nil { log.Fatalf("Failed to start proxy: %s", err) } diff --git a/proxy/http_proxy.go b/proxy/http_proxy.go index 79a4c3b..3d5f939 100644 --- a/proxy/http_proxy.go +++ b/proxy/http_proxy.go @@ -26,10 +26,10 @@ func (proxy StorageProxy) objectName(name string) string { return proxy.defaultPrefix + name } -func (proxy StorageProxy) Serve(port int64) error { +func (proxy StorageProxy) Serve(address string, port int64) error { http.HandleFunc("/", proxy.handler) - listener, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port)) + listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", address, port)) if err == nil { address := listener.Addr().String()