handle float64/string both

This commit is contained in:
Yasuhiro Matsumoto 2017-11-20 10:04:53 +09:00
parent 3002812c02
commit 81259792b7

View File

@ -3,6 +3,7 @@ package mastodon
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"net/url" "net/url"
"path" "path"
"strings" "strings"
@ -128,8 +129,12 @@ func (c *WSClient) handleWS(ctx context.Context, rawurl string, q chan Event) er
q <- &NotificationEvent{Notification: &notification} q <- &NotificationEvent{Notification: &notification}
} }
case "delete": case "delete":
if f, ok := s.Payload.(float64); ok {
q <- &DeleteEvent{ID: ID(fmt.Sprint(int64(f)))}
} else {
q <- &DeleteEvent{ID: ID(strings.TrimSpace(s.Payload.(string)))} q <- &DeleteEvent{ID: ID(strings.TrimSpace(s.Payload.(string)))}
} }
}
if err != nil { if err != nil {
q <- &ErrorEvent{err} q <- &ErrorEvent{err}
} }