package main import ( "encoding/json" "log" "github.com/Arman92/go-tdlib" ) func failOnError(err error, msg string) { if err != nil { log.Fatalf("%s: %s", msg, err) } } func logOnError(err error, msg string) { if err != nil { log.Printf("%s: %s", msg, err) } } func unmarshalCallbackQueryPayload(rawMsg *json.RawMessage) (tdlib.CallbackQueryPayload, error) { if rawMsg == nil { return nil, nil } var objMap map[string]interface{} err := json.Unmarshal(*rawMsg, &objMap) if err != nil { return nil, err } switch tdlib.CallbackQueryPayloadEnum(objMap["@type"].(string)) { case tdlib.CallbackQueryPayloadDataType: var callbackQueryPayloadData CallbackQueryPayloadData err := json.Unmarshal(*rawMsg, &callbackQueryPayloadData) return &callbackQueryPayloadData, err case tdlib.CallbackQueryPayloadGameType: var callbackQueryPayloadGame CallbackQueryPayloadGame err := json.Unmarshal(*rawMsg, &callbackQueryPayloadGame) return &callbackQueryPayloadGame, err default: return nil, fmt.Errorf("Error unmarshaling, unknown type:" + objMap["@type"].(string)) } }