Last active
December 12, 2017 21:48
-
-
Save tiagopotencia/87f49974d8c0609d9a265a53bc5ec147 to your computer and use it in GitHub Desktop.
Working with channels in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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