You can change an object from a specific type to a interface{}, and then change it back to the original type, using Type assertions. For example:

func main() {
    myObject := myType{"hello World!"}
    doSomething(myObject)
}

type myType struct {
    value string
}

func doSomething(object interface{}) {
    // At this point we can't read, for example, the "value" attribute on the received object.
    converted, ok := object.(myType)
    if ok {
        fmt.Print("success! ", converted.value)
    }
}
Previous on Go
Mastodon Mastodon