package main import ( "flag" "fmt" "os" "time" sendoverhttp "git.server.ky/slackcoder/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 %s [target]\n", os.Args[0]) fmt.Fprintln(flag.CommandLine.Output()) 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() if len(os.Args) == 2 { config.FilePath = os.Args[1] } if config.FilePath == "" { v, err := os.Getwd() exitOnErr(err) config.FilePath = v } s := sendoverhttp.NewServer(config) go s.Start() time.Sleep(250 * time.Millisecond) fmt.Println("press enter to exit") _, _ = fmt.Scanln() s.Stop() }