Skip to content

Commit

Permalink
Introduce address flag (#2)
Browse files Browse the repository at this point in the history
This can be useful in cirruslabs/cirrus-cli#121
where listening 0.0.0.0 will make the proxy reachable from other
containers that want to use the cache.
  • Loading branch information
edigaryev authored Oct 7, 2020
1 parent 8758349 commit 5ee81e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions proxy/http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5ee81e3

Please sign in to comment.