Quote from https://tour.golang.org/concurrency/2:
By default, sends and receives block until the other side is ready.
This allows goroutines to synchronize without explicit locks or
condition variables.
Channels are meant to work between goroutines, but you have only 1. So c1 <- 10
blocks execution, until someone (usually in other goroutine) receives the value.
To fix that:
package main
import (
"fmt"
)
func main() {
c1 := make(chan int)
go func() {
g1 := <- c1 // wait for value
fmt.Println("get g1: ", g1)
}()
fmt.Println("push c1: ")
c1 <- 10 // send value and wait until it is received.
}
Try executing it in The Go Playground.
I suggest you go through official Go concurrency tour starting from https://tour.golang.org/concurrency/1
EDIT: Another option is to use Buffered channel, like below. However making Buffered channel does not mean it has non-blocking send/receive operations. It just means it will block send after N values in queue, where N is always predefined number. Internally it will store sent values into an array, and block until values are received (like non-buffered channel) when that array is filled.
package main
import (
"fmt"
)
func main() {
c1 := make(chan int, 1) // buffers 1 value without blocking.
fmt.Println("push c1: ")
c1 <- 10
g1 := <- c1
fmt.Println("get g1: ", g1)
}
Try it on Go Playground.