我如何在golang中反思性地创建枚举实例?

I'm trying to create an instance of enum from its reflect.Type and value https://play.golang.org/p/PqklMe_Z4WX

Is there a way to create an instance of enum in golang with its type and possible value of constant?

Use reflect.New(t).Elem() to get a value and SetString to set the value.

// t is the reflect.Type for a Weekday
t := reflect.TypeOf(WeekDay("sunday"))

// v is reflect.Value for a WeekDay, initialized to the zero value ""
v := reflect.New(t).Elem()

// Set the value of v to "sunday"
v.SetString("sunday")

https://play.golang.org/p/qvoVIN2Ro7x