From f1a03b2082de8ed16c80ae5e030eda9c87c5e702 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Fri, 12 May 2023 21:26:25 -0400 Subject: Added client --- client/main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/client/main.go b/client/main.go index 5397384..47af004 100644 --- a/client/main.go +++ b/client/main.go @@ -6,6 +6,7 @@ import ( "encoding/base64" "flag" "fmt" + "io" "net/http" "os" "strings" @@ -116,5 +117,19 @@ func main() { if err != nil { panic(err) } + } else if flag.Arg(0) == "get" { + user := flag.Arg(1) + filename := flag.Arg(2) + response, _ := http.Get(servers[0] + "/storage/" + user + "/" + filename) + responseBodyBytes, _ := io.ReadAll(response.Body) + os.WriteFile(user + "/" + filename, responseBodyBytes, 0644) + } else if flag.Arg(0) == "post" { + filename := flag.Arg(1) + file, _ := os.Open(filename) + http.Post( + servers[0] + "/storage/" + id + "/" + filename, + "application/octet-stream", + file, + ) } } -- cgit v1.2.3-70-g09d2