Skip to content

Instantly share code, notes, and snippets.

@tiagopotencia
Last active December 12, 2017 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagopotencia/87f49974d8c0609d9a265a53bc5ec147 to your computer and use it in GitHub Desktop.
Save tiagopotencia/87f49974d8c0609d9a265a53bc5ec147 to your computer and use it in GitHub Desktop.
Working with channels in Go
package main
import (
"github.com/gin-gonic/gin"
"fmt"
)
var (
channel chan int
)
func main() {
channel = make(chan int)
eng := gin.New()
eng.GET("/", startChannel)
go listenChannel(channel)
eng.Run(":12345")
}
func startChannel(c *gin.Context){
fmt.Println("Received request!")
channel <- 1
return
}
func listenChannel(chann chan int){
for {
<- chann
fmt.Println("Trigged!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment