diff options
author | Slack Coder <slackcoder@server.ky> | 2022-05-17 11:00:28 -0500 |
---|---|---|
committer | Slack Coder <slackcoder@server.ky> | 2022-05-17 11:00:28 -0500 |
commit | 6c0acbc7c9f7418965c138d3b101e6d1e8f77ede (patch) | |
tree | 923f5ce38c36eae0f8f7c96cf0fe330eb0539222 /cmd | |
download | send-over-http-6c0acbc7c9f7418965c138d3b101e6d1e8f77ede.tar.xz |
initial commit
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/send-over-http/main.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/cmd/send-over-http/main.go b/cmd/send-over-http/main.go new file mode 100644 index 0000000..3c587ff --- /dev/null +++ b/cmd/send-over-http/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "flag" + "fmt" + "os" + "time" + + sendoverhttp "git.server.ky/cypher/send-over-http" +) + +func exitOnErr(err error) { + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(-1) + } +} + +func usage() { + fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s [target]\n", os.Args[0]) + fmt.Fprintln(flag.CommandLine.Output()) + fmt.Fprintf(flag.CommandLine.Output(), "\ttarget - file or directory to share (default: .)\n") + fmt.Fprintln(flag.CommandLine.Output()) +} + +func main() { + flag.Usage = usage + flag.Parse() + + var fp string + if len(os.Args) == 2 { + fp = os.Args[1] + } + if fp == "" { + v, err := os.Getwd() + exitOnErr(err) + fp = v + } + + s := sendoverhttp.NewServer(fp) + go s.Start() + + time.Sleep(250 * time.Millisecond) + fmt.Println("press enter to exit") + _, _ = fmt.Scanln() + + s.Stop() +} |