Description
How to reproduce
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
var signal chan string
func Run() {
router := gin.Default()
router.GET("/open", func(context *gin.Context) {
go func() {
select {
case s := <-signal:
fmt.Println(s)
}
}()
})
router.GET("/close", func(context *gin.Context) {
signal <- "close"
})
router.Run(":8001")
}
Expectations
curl http://localhost:8001/open
curl http://localhost:8001/close
// print close
Actual result
curl http://localhost:8001/open
curl http://localhost:8001/close
// hung up
Environment
- go version: 1.19
- gin version (or commit ref): 1.7.1
- operating system: MacOS
Comment From: mstmdev
Please ensure already initialize the channel signal
, for example signal = make(chan string)
.
Comment From: MikeJackOne
That's not the issue of gin, you don't even initialize the channel!