Compare commits

...

2 Commits

Author SHA1 Message Date
d510488d3f remove unnecessary output to stdout at beginning 2025-03-16 19:25:10 +09:00
f9b6c39353 change error handling 2025-03-16 19:24:56 +09:00
4 changed files with 15 additions and 12 deletions

View File

@@ -8,7 +8,6 @@ import (
) )
func main() { func main() {
fmt.Println("Hello, World!")
d := discord.Discord(os.Getenv("DISCORD_TOKEN"), os.Getenv("DISCORD_CHANNEL")) d := discord.Discord(os.Getenv("DISCORD_TOKEN"), os.Getenv("DISCORD_CHANNEL"))
tweetchannel := make(chan string, 1) tweetchannel := make(chan string, 1)
@@ -23,7 +22,12 @@ func main() {
for tweet := range tweetchannel { for tweet := range tweetchannel {
fmt.Println(tweet) fmt.Println(tweet)
for _, output := range outputs { for _, output := range outputs {
output.Write(tweet) err := output.Write(tweet)
if err != nil {
errstr := fmt.Sprintf("%s Error: %s", output.GetName(), err)
fmt.Fprintln(os.Stderr, errstr)
d.Write(errstr)
}
} }
} }
} }

View File

@@ -2,9 +2,7 @@ package output
import ( import (
"context" "context"
"fmt"
"log" "log"
"os"
"time" "time"
"github.com/bluesky-social/indigo/api/atproto" "github.com/bluesky-social/indigo/api/atproto"
@@ -60,9 +58,9 @@ func (bo *blueskyoutput) Write(str string) error {
} }
_, recerr := atproto.RepoCreateRecord(context.TODO(), cli, Recordinput) _, recerr := atproto.RepoCreateRecord(context.TODO(), cli, Recordinput)
if recerr != nil {
fmt.Fprint(os.Stderr, "bsky err: ")
fmt.Fprintln(os.Stderr, recerr)
}
return recerr return recerr
} }
func (bo *blueskyoutput) GetName() string {
return "bluesky"
}

View File

@@ -2,4 +2,5 @@ package output
type OutputInterface interface { type OutputInterface interface {
Write(string) error Write(string) error
GetName() string
} }

View File

@@ -47,9 +47,9 @@ func (to *twitteroutput) Write(str string) error {
} }
_, err := managetweet.Create(context.Background(), to.client, p) _, err := managetweet.Create(context.Background(), to.client, p)
if err != nil {
fmt.Fprint(os.Stderr, "twitter err: ")
fmt.Fprintln(os.Stderr, err)
}
return err return err
} }
func (to *twitteroutput) GetName() string {
return "twitter"
}