Added -b|--bind to bind to specific address
This commit is contained in:
parent
5beb1fc858
commit
4be011755b
|
@ -99,6 +99,7 @@ Available Commands:
|
|||
version Print version
|
||||
|
||||
Flags:
|
||||
-b, --bind string address to bind to (default "0.0.0.0")
|
||||
-c, --cache generate directory cache at startup
|
||||
--cache-file string path to optional persistent cache file
|
||||
-d, --debug expose debug endpoint
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
bind string
|
||||
cache bool
|
||||
cacheFile string
|
||||
debug bool
|
||||
|
@ -52,6 +53,7 @@ func Execute() {
|
|||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.Flags().StringVarP(&bind, "bind", "b", "0.0.0.0", "address to bind to")
|
||||
rootCmd.Flags().BoolVarP(&cache, "cache", "c", false, "generate directory cache at startup")
|
||||
rootCmd.Flags().StringVar(&cacheFile, "cache-file", "", "path to optional persistent cache file")
|
||||
rootCmd.Flags().BoolVarP(&debug, "debug", "d", false, "expose debug endpoint")
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var Version = "0.43.1"
|
||||
var Version = "0.43.2"
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
|
|
14
cmd/web.go
14
cmd/web.go
|
@ -12,6 +12,7 @@ import (
|
|||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"net/url"
|
||||
|
@ -835,6 +836,17 @@ func doNothing(http.ResponseWriter, *http.Request) {}
|
|||
func ServePage(args []string) error {
|
||||
fmt.Printf("roulette v%s\n\n", Version)
|
||||
|
||||
bindHost, err := net.LookupHost(bind)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bindAddr := net.ParseIP(bindHost[0])
|
||||
if bindAddr == nil {
|
||||
fmt.Println("Invalid bind address provided. Please specify an IPv4 or IPv6 address in dotted decimal or IPv6 format.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
paths, err := normalizePaths(args)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -909,7 +921,7 @@ func ServePage(args []string) error {
|
|||
http.Handle("/_/json", serveJsonDebugHandler(args, index))
|
||||
}
|
||||
|
||||
err = http.ListenAndServe(":"+strconv.FormatInt(int64(port), 10), nil)
|
||||
err = http.ListenAndServe(net.JoinHostPort(bind, strconv.FormatInt(int64(port), 10)), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue