Standard library / reflect

reflect.SelectCase

Describes a send, receive or default branch for Select. The Dir field determines which other fields are permitted. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
type SelectCase struct {  Dir  SelectDir  Chan Value  Send Value}

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() {  ch := make(chan int, 1)  v := reflect.ValueOf(ch)  ch <- 2  c := reflect.SelectCase{Dir: reflect.SelectRecv, Chan: v}  _, x, _ := reflect.Select([]reflect.SelectCase{c})  fmt.Println(x.Int())}
Go Reference