Go: invalid operation - type *map[key]value does not support indexing
<p>I'm trying to write a function that modifies original map that is passed by pointer but Go does not allow it. Let's say I have a big map and don't want to copy it back and forth.</p>

<p>The code that uses passing by value is working and is doing what I need but involves passing by value (<a href="https://play.golang.org/p/-UUiJ9vbMa" rel="noreferrer">playground</a>):</p>

<pre><code>package main

import "fmt"

type Currency string

type Amount struct {
    Currency Currency
    Value float32
}

type Balance map[Currency]float32

func (b Balance) Add(amount Amount) Balance {
    current, ok := b[amount.Currency]
    if ok {
        b[amount.Currency] = current + amount.Value
    } else {
        b[amount.Currency] = amount.Value
    }
    return b
}

func main() {
    b := Balance{Currency("USD"): 100.0}
    b = b.Add(Amount{Currency: Currency("USD"), Value: 5.0})

    fmt.Println("Balance: ", b)
}
</code></pre>

<p>But if I try to pass parameter as pointer like here (<a href="https://play.golang.org/p/kVCAt7074j" rel="noreferrer">playground</a>):</p>

<pre><code>func (b *Balance) Add(amount Amount) *Balance {
    current, ok := b[amount.Currency]
    if ok {
        b[amount.Currency] = current + amount.Value
    } else {
        b[amount.Currency] = amount.Value
    }
    return b
}
</code></pre>

<p>I'm getting compilation error:</p>

<pre><code>prog.go:15: invalid operation: b[amount.Currency] (type *Balance does not support indexing)
prog.go:17: invalid operation: b[amount.Currency] (type *Balance does not support indexing)
prog.go:19: invalid operation: b[amount.Currency] (type *Balance does not support indexing)
</code></pre>

<p>How should I deal with this?</p>