why are Tel.lookup[“idx”].value and Tel.m.value not the same values… i thought i was saving the reference in the map and when i put the reference out and update it i get a copy of the variable ?
playground link
https://goplay.space/#8HAHI9WG12-
package main
import (
“fmt”
)
func main() {
var Tel PkgVar = *Init()
Tel.lookup[“idx”].value = “NewValue”
fmt.Println(Tel.lookup[“idx”].value) <— why are these not the same?
fmt.Println(Tel.m.value) <–
}
func Init() *PkgVar {
var p PkgVar
p.m = metric{“Original_value”}
p.lookup = map[string]*metric{
“idx”: &p.m,
}
return &p
}
type PkgVar struct {
m metric
lookup map[string]*metric
}
type metric struct {
value string
}