Skip to content

Instantly share code, notes, and snippets.

@trasa
Created September 12, 2017 20:56
Show Gist options
  • Save trasa/f50a42779991e853d6c9d3b5a3b8e4eb to your computer and use it in GitHub Desktop.
Save trasa/f50a42779991e853d6c9d3b5a3b8e4eb to your computer and use it in GitHub Desktop.
// fragment
case "say":
// can we get this to work using the existing type from the map?
responsePrototypePtr := responseRegistry["say"]
log.Printf("responsePrototypePtr %s is at addr %p", reflect.TypeOf(responsePrototypePtr), responsePrototypePtr)
// allocate a new response based off of prototype
// this allocates a **Response
responseObjPtr := reflect.New(reflect.TypeOf(&responsePrototypePtr)).Interface()
log.Printf("responseObjPtr type %s, string %s", reflect.TypeOf(responseObjPtr), responseObjPtr)
// now need to allocate a Response
responseObj := reflect.New(reflect.TypeOf(responseObjPtr))
//responseObj = reflect.New(reflect.TypeOf(responseObjPtr.Elem().Interface().(Response)))
log.Printf("responseObj type %s at addr %p", reflect.TypeOf(responseObj), responseObj)
log.Printf("&responseObj type %s", reflect.TypeOf(&responseObj))
log.Println("what im trying to get:", reflect.TypeOf(&SayResponse{}))
log.Printf("does this equal? %s", reflect.TypeOf(&SayResponse{}) == reflect.TypeOf(responseObj))
if reflect.TypeOf(&SayResponse{}) != reflect.TypeOf(responseObj) {
panic("types are wrong")
}
log.Println("responseObj kind", reflect.TypeOf(responseObj).Kind())
response = decodeResponse(responseObj, rawMap)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment