title: Go: How to Synchronize and Share Data
body: <p>I'm writing a net/http server. My request handlers need access to some shared data that is updated by another go-routine. This go-routine keeps a single struct updated, and all of the net/http handlers need access to the same struct. </p>
  
  <pre><code>type MyData struct {
    Expiration time.Time
    A  string
    B  string
    C string
  }
  
  func update(data MyData) {
    go func() {
      for {
        if data.Expiration &gt;= time.Now() {
          // set A, B, C
        }
        // sleep
      }
    }()
  }
  </code></pre>
  
  <p>What's the best way to make a single, common MyData available to other go-routines? I was thinking a channel, but every reader of the channel should get the same MyData. The problem is that reading from a channel pops the item off the channel. I guess I'm looking for how to Peek() on the reader side, and Drain() on the writer side when it's time to update. </p>