This is how you can do it in go
:
package main
import (
"fmt"
)
type Event struct {
Data map[string]string
}
func main() {
e := new(Event)
e.Data = make(map[string]string)
e.Data["id"] = "THE_ID"
e.Data["filla_a"] = "THE_FILLA_A"
A(e)
}
func A(event *Event) {
temp := make(map[string]interface{})
temp["po_id"] = event.Data["id"]
B(temp, event)
fmt.Println(temp)
}
func B(temp map[string]interface{}, event *Event) map[string]interface{}{
temp["filla_a"] = event.Data["filla_a"]
return temp
}
I have assumed/made event
as struct
and declared the same in the program.
The map
in go
is a reference type (or better say it has pointer reference to internal data structures), so you do not need to pass a pointer
of map
, just pass/return the variable itself.
On the other hand struct
(the Type of e
in the main()
function) is value
type and need to be passed as a pointer to persist updates from called function.
NOTE: the new
keyword creates a pointer to the type. Thus the variable e
in the main()
function is actually a pointer to the Type Event
.
Go Playground: https://play.golang.org/p/Jbkm6z5a2Az
Hope it helps.