diff --git a/README.md b/README.md index 6c1017de..e075313f 100644 --- a/README.md +++ b/README.md @@ -53,11 +53,13 @@ You can either use flags or a JSON configuration file, which should have the fol } ``` -The `scope`, `allowCommands`, `allowEdit`, `allowNew` and `commands` options are the defaults for new users. To set a configuration file, you will need to pass the path with a flag, like this: `filemanager --config=/path/to/config.json`. +The `scope`, `allowCommands`, `allowEdit`, `allowNew` and `commands` options are the defaults for new users. To set a configuration file, you will need to pass the path with a flag, like this: `filemanager --config=/path/to/config.json`. Otherwise, you may not want to use a configuration file, which can be done using the following flags: ``` +-address string + Address to listen to (default is all of them) -allow-commands Default allow commands option (default true) -allow-edit @@ -69,9 +71,9 @@ Otherwise, you may not want to use a configuration file, which can be done using -database string Database path (default "./filemanager.db") -port string - HTTP Port (default "80") + HTTP Port (default is random) -scope string - Defualt scope for new users (default ".") + Default scope for new users (default ".") ``` # Features diff --git a/cmd/filemanager/main.go b/cmd/filemanager/main.go index fc644bfb..2f141fdf 100644 --- a/cmd/filemanager/main.go +++ b/cmd/filemanager/main.go @@ -5,6 +5,7 @@ import ( "flag" "fmt" "io/ioutil" + "net" "net/http" "strconv" "strings" @@ -27,6 +28,7 @@ type confFile struct { } var ( + addr string config string database string scope string @@ -39,7 +41,8 @@ var ( func init() { flag.StringVar(&config, "config", "", "JSON configuration file") - flag.StringVar(&port, "port", "8080", "HTTP Port") + flag.StringVar(&port, "port", "0", "HTTP Port (default is random)") + flag.StringVar(&addr, "address", "", "Address to listen to (default is all of them)") flag.StringVar(&database, "database", "./filemanager.db", "Database path") flag.StringVar(&scope, "scope", ".", "Default scope for new users") flag.StringVar(&commands, "commands", "git svn hg", "Space separated commands available for new users") @@ -72,8 +75,13 @@ func main() { fm.SetBaseURL("/") fm.SetPrefixURL("/") - fmt.Println("Starting filemanager on *:" + port) - if err := http.ListenAndServe(":"+port, fm); err != nil { + listener, err := net.Listen("tcp", addr+":"+port) + if err != nil { + panic(err) + } + + fmt.Println("Listening on", listener.Addr().String()) + if err := http.Serve(listener, fm); err != nil { panic(err) } }