Go goroutine lock and unlock
<p>I been reading about goroutines and the sync package and my question is... Do I always need to lock unlock when reading writting to data on different goroutines?</p>

<p>For example I have a variable on my server</p>

<pre><code>config := make(map[string]string)
</code></pre>

<p>Then on different goroutines I want to read from config. Is it safe to read without using sync or it is not?</p>

<p>I guess writting needs to be done using the sync package. but I am not sure about reading</p>

<p>For example I have a simple in-memory cache system</p>

<pre><code>type Cache interface {
    Get(key string) interface{}
    Put(key string, expires int64, value interface{})
}

// MemoryCache represents a memory type of cache
type MemoryCache struct {
    c map[string]*MemoryCacheValue
    rw sync.RWMutex
}

// MemoryCacheValue represents a memory cache value
type MemoryCacheValue struct {
    value interface{}
    expires int64
}

// NewMemoryCache creates a new memory cache
func NewMemoryCache() Cache {
    return &amp;MemoryCache{
        c: make(map[string]*MemoryCacheValue),
    }
}

// Get stores something into the cache
func (m *MemoryCache) Get(key string) interface{} {
    if v, ok := m.c[key]; ok {
        return v
    }
    return nil
}

// Put retrieves something from the cache
func (m *MemoryCache) Put(key string, expires int64, value interface{}) {
    m.rw.Lock()
    m.c[key] = &amp;MemoryCacheValue{
        value,
        time.Now().Unix() + expires,
    }
    m.rw.Unlock()
}
</code></pre>

<p>I am acting safe here or I still need to lock unlock when I want to only read?</p>