1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
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 <options> [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()
}
|