So here is what I am trying to do.
A single Ledger .Which is of the type
map[string]interface{}
The problem is every-time anyone wants to read from the ledger he has to copy the value to a local variable and perform operations on it. This ‘copy’ might might lead to performance issues in my project.
Instead I want the map of hold references of the object which is inserted into it. This way anyone using the map doesnt have to copy into local variable rather point to the original object/modify the original object(its okay to modify) and get things done.Therefore changing the map structure to
map[string]*interface{}
Now the question : Is this the right thinking? Does golang gives any other alternate tool/mechanism to implement what I am willing to do?
Moving on , now if I try this , its failing
s:= "some random string"
singleLedger := make(map[string]*interface{})
singleLedger["first_entry"] = &s
What is going wrong?
What I want to do is it possible?
Just make int map[string]interface{} and only store pointers.
Wrap getting and setting values into functions/methods and guarantee through them that only pointers get stored.
Alternatively, you could make s an interface{}, I’m not sure though if you can reconstruct its original type then. https://play.golang.org/p/DIagkFCm_lB