diff --git a/cmd/server.go b/cmd/server.go index c5309d3..73adb6b 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -26,16 +26,7 @@ var serveCmd = &cobra.Command{ func init() { rootCmd.AddCommand(serveCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - serveCmd.PersistentFlags().String("port", "1302", "Port for server to listen on") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // serveCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + serveCmd.PersistentFlags().StringP("port", "p", "1302", "Port for server to listen on") } func setServerParameters(cmd *cobra.Command) error { diff --git a/cmd/serverFunc.go b/cmd/serverFunc.go index 8b5625f..87bc5ff 100644 --- a/cmd/serverFunc.go +++ b/cmd/serverFunc.go @@ -6,6 +6,7 @@ import ( "io" "io/fs" "log" + "mime/multipart" "net/http" "os" ) @@ -38,11 +39,20 @@ func uploadFile(w http.ResponseWriter, r *http.Request) { if err != nil { log.Printf("Error happened opening file: %v\n", err) } + isDone := make(chan bool) - _, err = io.Copy(f, file) + go copyTo(isDone, f, file) + + <-isDone + log.Printf("Successfully copied file!\n") +} + +func copyTo(isDone chan bool, f *os.File, file multipart.File) { + _, err := io.Copy(f, file) if err != nil { log.Printf("Error happened writing file: %v\n", err) } + isDone <- true } func server() {