I need to pass an interface of a struct type by reference as shown below. Since, I can't use pointers of interface to struct type variables, how should I change the below code to modify te
value to 10
?.
package main
import (
"fmt"
)
func another(te *interface{}) {
*te = check{Val: 10}
}
func some(te *interface{}) {
*te = check{Val: 20}
another(te)
}
type check struct {
Val int
}
func main() {
a := check{Val: 100}
p := &a
fmt.Println(*p)
some(p)
fmt.Println(*p)
}
Thanks!
P.S I have read that passing pointers to interfaces is not a very good practice. Kindly let me know what could be a better way to handle it