-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.go
55 lines (45 loc) · 1022 Bytes
/
client.go
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
// +build ignore
package main
import (
"fmt"
"flag"
"log"
"net/http"
"os"
"io/ioutil"
"github.com/gorilla/websocket"
)
var upgrader = websocket.Upgrader{} // use default options
func main() {
flag.Parse()
var hostName string
if flag.NArg() < 1 {
log.Fatal("Filename not specified")
}
if (flag.NArg() == 2) {
hostName = flag.Args()[1]
addr := flag.String("addr", hostName+":8080", "http service address")
_ = addr
} else {
addr := flag.String("addr", "localhost:8080", "http service address")
_ = addr
}
// Get filename
filename := flag.Args()[0]
// Upload file to server
upload(filename, hostName)
}
func upload(filename string, hostName string) {
file, err := os.Open("./send-files/"+filename)
if err != nil {
panic(err)
}
defer file.Close()
res, err := http.Post("http://"+hostName+":8080/upload?filename="+filename, "binary/octet-stream", file)
if err != nil {
panic(err)
}
defer res.Body.Close()
message, _ := ioutil.ReadAll(res.Body)
fmt.Printf(string(message))
}