接受interface {}参数的函数如何更新通过引用调用的值?

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?

Here you don't need to use the intermediate variable decodedSettings. Instead, using the readSettings pointer you pass in directly will cause the JSON package to deserialise to that instead.

Your code will become:

func GetSettings(settingsToPopulate interface{}) error {
    file, _ := os.Open("/tmp/settings.json")
    return json.NewDecoder(file).Decode(settingsToPopulate)
}