Use reflect.New with a reflect.Type to dynamically allocate a zero-valued pointer to any Go type.
Use reflect.New with a type value to allocate a new zero-valued instance of that type as a pointer. Pass the result of reflect.TypeOf (or a stored reflect.Type) to reflect.New, then call .Interface() to get the typed pointer.
import "reflect"
// Allocate a new *MyStruct dynamically
t := reflect.TypeOf(MyStruct{})
ptr := reflect.New(t).Interface().(*MyStruct)
reflect.New creates a new, empty object of a specific type when you only know the type at runtime. It's like asking the computer to build a fresh box of a certain shape without you having to write the code for that specific shape beforehand. You use this when writing generic code that needs to handle many different types.