Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create an alternative done function
- newDoneFunc := func (string, bool, time.Time) {
- println("Hi!")
- }
- message := pubsub.Message{}
- //Get a reflectable value of message
- messageValue := reflect.ValueOf(message)
- //Get message's doneFunc field
- doneFuncField := messageValue.FieldByName("doneFunc")
- //Get the address of the field
- doneFuncFieldAddress := doneFuncField.UnsafeAddr()
- //Create a pointer based on the address
- doneFuncFieldPointer := unsafe.Pointer(doneFuncFieldAddress)
- //Create a new, exported field element that points to the original
- accessibleDoneFuncField := reflect.NewAt(doneFuncField.Type(), doneFuncFieldPointer).Elem()
- //Set the field with the alternative doneFunc
- accessibleDoneFuncField.Set(reflect.ValueOf(newDoneFunc))
Add Comment
Please, Sign In to add comment