Fixed Code
This commit is contained in:
parent
dbd9060591
commit
166c95b7bb
9
main.go
9
main.go
|
@ -73,7 +73,7 @@ func streamResponse(w http.ResponseWriter, messages <-chan string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for msg := range messages {
|
for msg := range messages {
|
||||||
formattedMessage := createStreamResponse(msg)
|
formattedMessage := createStreamResponse("fromLanguage", "toLanguage", msg) // Adjust as needed
|
||||||
fmt.Fprintf(w, " %s\n\n", formattedMessage)
|
fmt.Fprintf(w, " %s\n\n", formattedMessage)
|
||||||
flusher.Flush()
|
flusher.Flush()
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ func downloadPackages(w http.ResponseWriter, fromLanguage, toLanguage string) {
|
||||||
messages := make(chan string)
|
messages := make(chan string)
|
||||||
defer close(messages)
|
defer close(messages)
|
||||||
|
|
||||||
go streamResponse(w, fromLanguage, toLanguage, messages)
|
go streamResponse(w, messages)
|
||||||
|
|
||||||
cmd := exec.Command(linux, "translator/download.py", fromLanguage, toLanguage)
|
cmd := exec.Command(linux, "translator/download.py", fromLanguage, toLanguage)
|
||||||
output, err := cmd.StdoutPipe()
|
output, err := cmd.StdoutPipe()
|
||||||
|
@ -193,11 +193,6 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert byte slices to strings
|
|
||||||
msg.Message = string(body)
|
|
||||||
msg.From = string(msg.From)
|
|
||||||
msg.To = string(msg.To)
|
|
||||||
|
|
||||||
if len(msg.From) > 2 || len(msg.To) > 2 {
|
if len(msg.From) > 2 || len(msg.To) > 2 {
|
||||||
http.Error(w, "From and To fields should not be longer than 2 letters.", http.StatusBadRequest)
|
http.Error(w, "From and To fields should not be longer than 2 letters.", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue