I have a package called server that contains a Settings struct. It contains code like this:
type Settings struct {
foobar String
}
func example() {
readSettings := Settings{}
err := storage.GetSettings(&readSettings)
// Problem: at this point, readSettings has not been changed!
}
My problem is that readSettings is not being updated.
In the storage package, there is a function GetSettings:
func GetSettings(settingsToPopulate interface{}) error {
file, _ := os.Open("/tmp/settings.json")
var decodedSettings interface{}
json.NewDecoder(file).Decode(&decodedSettings)
settingsToPopulate = decodedSettings
return nil
}
My constraints are that the Settings struct must remain in server, and the IO method GetSettings much remain in storage.
I can't make GetSettings just accept a Settings struct, because that would cause a circular dependency.
How can I make the reference parameter of GetSettings be updated?