Improvements #2

Merged
raul merged 10 commits from testing into main 2024-05-30 08:09:07 +02:00
2 changed files with 12 additions and 11 deletions
Showing only changes of commit 12d3498055 - Show all commits

View File

@ -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 {

View File

@ -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() {