Improvements #2
|
@ -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 {
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue