Skip to content

Commit

Permalink
Bugfix/issue 158 system error on filtered stream (#159)
Browse files Browse the repository at this point in the history
* added to handle base64 disconnection

* renamed for disconnection errors

* updated the examples

* updating the example
  • Loading branch information
g8rswimmer authored Dec 11, 2022
1 parent 928bdc2 commit f1d01da
Show file tree
Hide file tree
Showing 4 changed files with 383 additions and 58 deletions.
11 changes: 10 additions & 1 deletion v2/_examples/tweets/filtered-stream/tweet-search-stream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"encoding/json"
"flag"
"fmt"
twitter "github.com/g8rswimmer/go-twitter/v2"
"log"
"net/http"
"os"
"os/signal"
"syscall"

twitter "github.com/g8rswimmer/go-twitter/v2"
)

type authorize struct {
Expand Down Expand Up @@ -75,6 +76,14 @@ func main() {
outputFile.WriteString(fmt.Sprintf("system: %s\n\n", string(smb)))
outputFile.Sync()
fmt.Println("system")
case de := <-tweetStream.DisconnectionError():
ded, err := json.Marshal(de)
if err != nil {
fmt.Printf("error decoding disconnect message %v", err)
}
outputFile.WriteString(fmt.Sprintf("disconnect: %s\n\n", string(ded)))
outputFile.Sync()
fmt.Println("disconnect")
case strErr := <-tweetStream.Err():
outputFile.WriteString(fmt.Sprintf("error: %v\n\n", strErr))
outputFile.Sync()
Expand Down
13 changes: 11 additions & 2 deletions v2/_examples/tweets/volume-stream/tweet-sample-stream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"encoding/json"
"flag"
"fmt"
twitter "github.com/g8rswimmer/go-twitter/v2"
"log"
"net/http"
"os"
"os/signal"
"syscall"

twitter "github.com/g8rswimmer/go-twitter/v2"
)

type authorize struct {
Expand Down Expand Up @@ -52,7 +53,7 @@ func main() {
}

ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
func() {
defer tweetStream.Close()
for {
Expand All @@ -76,6 +77,14 @@ func main() {
outputFile.WriteString(fmt.Sprintf("system: %s\n\n", string(smb)))
outputFile.Sync()
fmt.Println("system")
case de := <-tweetStream.DisconnectionError():
ded, err := json.Marshal(de)
if err != nil {
fmt.Printf("error decoding disconnect message %v", err)
}
outputFile.WriteString(fmt.Sprintf("disconnect: %s\n\n", string(ded)))
outputFile.Sync()
fmt.Println("disconnect")
case strErr := <-tweetStream.Err():
outputFile.WriteString(fmt.Sprintf("error: %v\n\n", strErr))
outputFile.Sync()
Expand Down
Loading

0 comments on commit f1d01da

Please sign in to comment.