Standard library / reflect

reflect.ChanOf()

Construct a channel type with a direction and element type. It does not create a channel. Expected stdout: '<-chan int\n'.

Formal Syntax & Structure

go syntaxgo
func ChanOf(dir ChanDir, t Type) Type

Parameters & Attributes

NameTypeDescription
dirChanDirChannel direction.
tTypeElement type of the new composite type.

Return Value

Type

Construct a channel type with a direction and element type.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() { fmt.Println(reflect.ChanOf(reflect.RecvDir, reflect.TypeOf(0))) }
Go Reference