mirror of
https://github.com/SourceFellows/gobuch.git
synced 2025-07-21 07:30:44 +02:00
initial import
This commit is contained in:
24
best-practices/context-http-server/main.go
Normal file
24
best-practices/context-http-server/main.go
Normal file
@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func handleCall(res http.ResponseWriter, req *http.Request) {
|
||||
ctx := req.Context()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
res.Write([]byte("end"))
|
||||
fmt.Println("clsoing connection to client")
|
||||
return
|
||||
case <-time.After(20 * time.Second):
|
||||
fmt.Fprintln(res, "Hello World")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", handleCall)
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
Reference in New Issue
Block a user