title: Thread save map in text template
body: <p>I wrote thread safe map using RWMutex. You can see code below.</p>
  
  <pre><code>
  type SyncMap struct {
      sync.RWMutex
      db map[string]interface{}
  }
  
  func NewSyncMap() *SyncMap {
      ctx := new(SyncMap)
      ctx.Clear()
      return ctx
  }
  
  func (ctx *SyncMap) Set(key string, value interface{}) {
      ctx.Lock()
      ctx.db[key] = value
      ctx.Unlock()
  }
  
  func (ctx *SyncMap) Get(key string) interface{} {
      ctx.RLock()
      v := ctx.db[key]
      ctx.RUnlock()
      return v
  }
  
  func (ctx *SyncMap) Delete(key string) {
      ctx.Lock()
      delete(ctx.db, key)
      ctx.Unlock()
  }
  </code></pre>
  
  <p>And after I need to execute <strong>template.Template</strong> and put there that map.
  I have two variant:</p>
  
  <ol>
  <li>Make full copy of map (Not my idea of fun)</li>
  <li>Just put reference to <strong>Map.db</strong> inside</li>
  </ol>
  
  <pre><code>func (ctx *SyncMap) Map() map[string]interface{} {
      return ctx.db
  }
  
  </code></pre>
  
  <p>But is it thread safe for reading?</p>