c := make(chan string)
c <- value
fmt.Println("check:", <-c)
fmt.Println("at the end")
}
Running above code, the http server just hang. Why is the form not able to be presented?
My intent is to get a user input before proceeding to the rest of the code. Actually intending to present another user input form after the first feedback(user input), but found out that both form will automatically be run at once, hence was thinking of using a channel to wait for first user input before gong for 2nd user input. But putting a channel hangs the server.
I’m very new to golang, and as new to do any coding. Is my understanding of http.Server wrong here? Isn’t the code supposed to run line by line?
In reply to your comments, I have 2 questions as it makes me more confusing.
The channel statement is after the form statement. I supposed we have not come to channel statement, the form supposed to be presented right? I can’t even see the form.
For channel c, I thought I read it immediately after that:
fmt.Println(“check:”, <-c)
But still in the same main function. Does channel be only used in go routine? I cannot use in the same function?
Sorry, still trying to understand some basic concept.
Writing to HTTP responses is usually buffered and the current form is probably not filling the buffer, such it is not yet sent. This buffering happens in multiple layers, the res might be buffered, the runtime might have an additional buffer for streams between internal and external, the network stack of the operating system might have another buffer.
As I said it is not getting there, as it can not pass the unbuffered send.
A handler handles a single request. Not more, not less.
You need other means of transfering data from previous requests to another. A database is often used for longtime persisting data and KV stores like redis for short term persistence.