I am using the following function to upload videos (around 1 gb). It works properly.My requirements are (these checks are being done in a different function using the mediainfo library): check if the file is a valid video filecheck video countcheck audio count check  video resolution etcIs this the right way to do it? How can I improve on this? I am just trying to get my head around this.func UploadCreative(jwtString string, r *http.Request, w http.ResponseWriter) {    userUUID, err := settings.GetUserUUIDFromJWT(jwtString)    methodName := service.UploadCreative    if err != nil {        settings.LogError(jwt.ErrSignatureInvalid, methodName, Invalid Token)        response, _ := json.Marshal(settings.ErrInternalServer)        settings.WriteResponse(w, http.StatusInternalServerError, response)        // return http.StatusInternalServerError, response    }    // TBD: Send the correct response    type Response struct {        Message string `json:message`    }    // temp folder path    chunkDirPath := ./creatives/.uploads/ + userUUID    // create folder    err = os.MkdirAll(chunkDirPath, 02750)    if err != nil {        settings.LogError(err, methodName, Failed to create folders)        response, _ := json.Marshal(settings.ErrInternalServer)        settings.WriteResponse(w, http.StatusInternalServerError, response)    }    // Get file handle from multipart request    var file io.Reader    mr, err := r.MultipartReader()    if err != nil {        settings.LogError(err, methodName, Error reading form data)        response, _ := json.Marshal(settings.ErrInternalServer)        settings.WriteResponse(w, http.StatusInternalServerError, response)    }    // Read multipart body until the file part    for {        part, err := mr.NextPart()        if err == io.EOF {            break        }        if part.FormName() == file {            file = part            break        }    }    if file == nil {        settings.LogError(nil, methodName, Missing file from multipart request)        response, _ := json.Marshal(settings.ErrInternalServer)        settings.WriteResponse(w, http.StatusInternalServerError, response)    }    if err != nil {        settings.LogError(err, methodName, Error creating file)        response, _ := json.Marshal(settings.ErrInternalServer)        settings.WriteResponse(w, http.StatusInternalServerError, response)    }    // Pipe file data from the request body to a preprocessing goroutine    //  - Guess content type    preprocessReader, preprocessWriter := io.Pipe()    totalBytes := 0    quit := make(chan bool)    continueUpload := make(chan bool)    errs := make(chan error)    go func() {        for {            select {            case <-quit:                fmt.Println(quit)                preprocessWriter.Close()                preprocessReader.Close()                return            default:                buf := make([]byte, 1024)                bytesRead, err := file.Read(buf)                if err != nil {                    if err != io.EOF {                        settings.LogError(err, methodName, Unable to read data from request body)                    }                    preprocessWriter.Close()                    return                }                // Increment size                totalBytes += bytesRead                // Pass file data to data backend                preprocessWriter.Write(buf[:bytesRead])            }        }    }()    // Create files    tempFile := chunkDirPath + /tempFile    dst, err := os.Create(tempFile)    defer dst.Close()    go func() {        for {            select {            case <-quit:                preprocessWriter.Close()                preprocessReader.Close()                return            default:                fileInfo, _ := os.Stat(tempFile)                fileSize := fileInfo.Size()                if fileSize > 1024 {                    ok, _, err := mediaInfo.CheckMedia(tempFile)                    if ok {                        continueUpload <- true                        errs <- nil                        return                    }                    preprocessWriter.Close()                    preprocessReader.Close()                    continueUpload <- false                    errs <- err                    return                }            }        }    }()    // Copy file data from the client request body    // to the file system    _, err = io.Copy(dst, preprocessReader)    validFile := <-continueUpload    errString := <-errs    if validFile {        response, _ := json.Marshal(&Response{File uploaded successfully})        settings.WriteResponse(w, http.StatusOK, response)    } else {        response, _ := json.Marshal(&Response{fmt.Sprintf(Upload cancelled: %s, errString.Error())})        settings.WriteResponse(w, http.StatusOK, response)    }}
Uploading large videos using go
go