aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorSlack Coder <slackcoder@server.ky>2023-09-14 13:54:49 -0500
committerSlack Coder <slackcoder@server.ky>2023-09-14 15:52:56 -0500
commit33af09195b60fd7364e2190934717a9345ce6cad (patch)
tree947017bc407ff86040f0c4c162268089e8c8e6aa /cmd
parente4d26432d4ef366c9e4b969d4fdb8d4728b545b3 (diff)
downloadsend-over-http-33af09195b60fd7364e2190934717a9345ce6cad.tar.xz
Allow user to set network address
Give the user the ability to set which network address to listen on and the network type (IP 4 or 6 etc.). Randomly choose an available port to avoid conflicting with other services listening on a predefined one.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/send-over-http/main.go21
1 files changed, 14 insertions, 7 deletions
diff --git a/cmd/send-over-http/main.go b/cmd/send-over-http/main.go
index 3c587ff..4bd9750 100644
--- a/cmd/send-over-http/main.go
+++ b/cmd/send-over-http/main.go
@@ -17,27 +17,34 @@ func exitOnErr(err error) {
}
func usage() {
- fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s [target]\n", os.Args[0])
+ fmt.Fprintf(flag.CommandLine.Output(), "Usage %s <options> [target]\n", os.Args[0])
fmt.Fprintln(flag.CommandLine.Output())
- fmt.Fprintf(flag.CommandLine.Output(), "\ttarget - file or directory to share (default: .)\n")
+ fmt.Fprintf(flag.CommandLine.Output(), " target: file or directory to share (default: .)\n")
+ fmt.Fprintln(flag.CommandLine.Output())
+ fmt.Fprintln(flag.CommandLine.Output(), "Options:")
+ fmt.Fprintln(flag.CommandLine.Output())
+ flag.PrintDefaults()
fmt.Fprintln(flag.CommandLine.Output())
}
func main() {
+ config := sendoverhttp.Config{}
+
+ flag.StringVar(&config.Network, "net", "tcp", "network type to listen on (tcp, tcp4, tcp6)")
+ flag.StringVar(&config.ListenAddress, "address", "", "network address to accept connections (example: 127.0.0.1:1234)")
flag.Usage = usage
flag.Parse()
- var fp string
if len(os.Args) == 2 {
- fp = os.Args[1]
+ config.FilePath = os.Args[1]
}
- if fp == "" {
+ if config.FilePath == "" {
v, err := os.Getwd()
exitOnErr(err)
- fp = v
+ config.FilePath = v
}
- s := sendoverhttp.NewServer(fp)
+ s := sendoverhttp.NewServer(config)
go s.Start()
time.Sleep(250 * time.Millisecond)