Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce address flag #2

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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