> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Go Directional Channel

A directional channel in Go is a channel type constrained at compile-time to permit only unidirectional data flow—either sending or receiving. By restricting a channel's operations via its type signature, Go enforces type safety and prevents invalid operations, such as writing to a channel that should only be read from, or closing a channel from the receiving end.

## Syntax and Type Signatures

Directionality is defined by the position of the arrow operator (`<-`) relative to the `chan` keyword. The arrow visually represents the direction of data flow.

```go theme={"dark"}
chan T     // Bidirectional: permits sending, receiving, and closing
chan<- T   // Send-only: permits sending and closing; prohibits receiving
<-chan T   // Receive-only: permits receiving; prohibits sending and closing
```

## Type Conversion and Assignment

Go allows implicit, one-way type conversion from a bidirectional channel to a directional channel. This typically occurs at function boundaries where a bidirectional channel is passed as an argument to a parameter expecting a directional channel.

```go theme={"dark"}
bi := make(chan int)

// Implicit conversion from bidirectional to directional
var sendOnly chan<- int = bi
var recvOnly <-chan int = bi
```

The reverse is strictly prohibited. A directional channel cannot be cast or converted back into a bidirectional channel, nor can a send-only channel be converted to a receive-only channel.

```go theme={"dark"}
// Compile-time errors:
// bi = sendOnly 
// bi = (chan int)(recvOnly)
```

## Operation Constraints

The Go compiler enforces strict rules based on the channel's directional type. Violating these rules results in compile-time errors, not runtime panics.

### Receive-Only Channels (`<-chan T`)

* **Allowed:** Reading data (`val := <-ch`), reading with the comma-ok idiom (`val, ok := <-ch`), and iterating via `range`.
* **Prohibited:** Sending data (`ch <- val`) and closing the channel (`close(ch)`).

### Send-Only Channels (`chan<- T`)

* **Allowed:** Sending data (`ch <- val`) and closing the channel (`close(ch)`).
* **Prohibited:** Reading data (`<-ch`) and iterating via `range`.

## Mechanical Demonstration

The following code block illustrates the compiler enforcement of directional channel constraints within a function scope:

```go theme={"dark"}
func enforceDirection(in <-chan int, out chan<- int) {
    // VALID OPERATIONS
    val := <-in      // Reading from receive-only
    out <- val       // Writing to send-only
    close(out)       // Closing send-only

    // INVALID OPERATIONS (Will cause compile-time errors)
    // in <- 1       // invalid operation: in <- 1 (send to receive-only type <-chan int)
    // close(in)     // invalid operation: close(in) (cannot close receive-only channel)
    // <-out         // invalid operation: <-out (receive from send-only type chan<- int)
}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Go Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
