test
This commit is contained in:
parent
39c6a628cd
commit
ff1780446b
34
utils.go
34
utils.go
@ -1,11 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/Arman92/go-tdlib"
|
||||
)
|
||||
|
||||
func failOnError(err error, msg string) {
|
||||
@ -19,33 +15,3 @@ func logOnError(err error, msg string) {
|
||||
log.Printf("%s: %s", msg, err)
|
||||
}
|
||||
}
|
||||
|
||||
func unmarshalCallbackQueryPayload(msg []byte) (tdlib.CallbackQueryPayload, error) {
|
||||
var rawMsg *json.RawMessage
|
||||
|
||||
rawMsg = byte(msg)
|
||||
|
||||
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 tdlib.CallbackQueryPayloadData
|
||||
err := json.Unmarshal(*rawMsg, &callbackQueryPayloadData)
|
||||
return &callbackQueryPayloadData, err
|
||||
|
||||
case tdlib.CallbackQueryPayloadGameType:
|
||||
var callbackQueryPayloadGame tdlib.CallbackQueryPayloadGame
|
||||
err := json.Unmarshal(*rawMsg, &callbackQueryPayloadGame)
|
||||
return &callbackQueryPayloadGame, err
|
||||
|
||||
default:
|
||||
return nil, fmt.Errorf("Error unmarshaling, unknown type:" + objMap["@type"].(string))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user