package main

import "fmt"

type User struct {
	ID   int
	Name string
}

func main() {
	c := make(chan User, 1)
	u := User{ID: 1, Name: "Rob"}

	// Write the value into the channel
	c <- u

	// Read the value off the channel
	u1 := <-c
	fmt.Printf("read successful: %+v\n", u1)

	// Close the channel
	close(c)

	// Read off the channel again...
	u1 = <-c
	fmt.Printf("read closed: %+v\n", u1)

	var ok bool

	// Proper way to read
	if u1, ok = <-c; ok {
		fmt.Printf("read successful: %+v\n", u1)
	} else {
		fmt.Println("attempted read of closed channel, ignore value returned")
	}
}
