Golang reflect.MakeChan() function example

package reflect

Golang reflect.MakeChan() function usage example.

 package main

 import (
  "fmt"
  "reflect"
 )

 func main() {
  var str chan string // channel string type

  var strValue reflect.Value = reflect.ValueOf(&str)

  indirectStr := reflect.Indirect(strValue)

  //fmt.Println("str type : ", indirectStr.Kind())

  // create new channel
  value := reflect.MakeChan(indirectStr.Type(), 1024)

  fmt.Printf("Value type is [%v] and capacity [%v] bytes.", value.Kind(), value.Cap())
 }

Reference :

http://golang.org/pkg/reflect/#MakeChan

Advertisement