So I have the two following methods:
func Marshal(in interface{}) (out []byte, err error)
func readDocument(r io.Reader) ([]byte, error)
In my code I do the following:
queryDoc, err := readDocument(client) // querydoc is slice of len 408
if something {
queryDoc, err := bson.Marshal(something)
newDocLen := len(queryDoc) // len is now 200
}
len(queryDoc) // len is 408????
For some reason, queryDoc doesn't get updated with the unmarshalling. If however, I assign to an intermediate value, it works:
queryDoc, err := readDocument(client) // querydoc is slice of len 408
if something {
q, err := bson.Marshal(something)
queryDoc = q
newDocLen := len(queryDoc) // len is now 200
}
len(queryDoc) // len is 200
Since I'm assigning the return value to queryDoc in the first example, shouldn't the variable queryDoc now reference the new array?