convert struct pointer to interface{}
问题 If I have: type foo struct{ } func bar(baz interface{}) { } The above are set in stone - I can't change foo or bar. Additionally, baz must converted back to a foo struct pointer inside bar. How do I cast &foo{} to interface{} so I can use it as a parameter when calling bar? 回答1: To turn *foo into an interface{} is trivial: f := &foo{} bar(f) // every type implements interface{}. Nothing special required In order to get back to a *foo , you can either do a type assertion : func bar(baz