-
Notifications
You must be signed in to change notification settings - Fork 0
Golang
jaeseok.an edited this page Apr 12, 2019
·
4 revisions
- bidirectionnal channel 은 unidirectional channel로 convert가능
func f(x <-chan int) int { return n } func main() { c make(chan int) n := f(c) }
- closed channel
- read
x, ok <- mychan if !ok { return false }
- write는 panic발생
- read
func main() {
buf := new(bytes.Buffer)
var x bool = true
err := binary.Write(buf, binary.LittleEndian, x)
if err != nil {
fmt.Println("binary.Write failed:", err)
}
fmt.Printf("% x \n", buf.Bytes())
mybytes := buf.Bytes()
//binary to bool
var y bool = false
bufreader := bytes.NewReader(mybytes)
err = binary.Read(bufreader, binary.LittleEndian, &y)
if err != nil {
fmt.Println("binary.Read failed:", err)
}
fmt.Printf("read bool + %v \n", y)
}
test