# Channel Direction (uni/bi)

{% hint style="warning" %}
This page is under active revision, content may be updated without notice
{% endhint %}

By default channels can receive and send, but channels direction can be controlled by restricting them to either send or receive (applicable only for method/func signature). This ensures safety where required. For example

```go
func Ping( c chan<- string, msg string){
  c <- msg
}
func Pong( c <-chan string, cc chan<- string ){
  msg := <-c
  cc <- msg
}
func main(){
  pic := make(chan string, 1)
  poc := make(chan string, 1)
  Ping(pic, "Pass the message")
  Pong(pic, poc)
  fmt.Println(<-poc)
}
```

#### Channels with Range and Close

Channel can be iterated over using range and can be closed. Channel, closed once will allow no more values to passed across.

```go
func fib(num int, c chan int) {
  x, y := 0, 1
  for i := 0; i < num; i++ {
    c <- x
    x, y = y, x+y
  }
  close(c)
}
func main() {
  c := make(chan int, 10)
  go fib(cap(c), c)
  for i := range c {
    fmt.Println(i)
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://golang.bagwanpankaj.com/advanced-go/channel-direction-uni-bi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
