Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Post a message for every line of stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhammond committed May 9, 2014
1 parent 47a78e6 commit 8ce046d
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions slackcat.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"bufio"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -95,19 +95,21 @@ func main() {
if err != nil {
log.Fatalf("Coult not read config: %v", err)
}
bytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("Cannot read STDIN: %v", err)
}

msg := SlackMsg{
Parse: "full",
Username: username(),
Text: string(bytes),
}
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
msg := SlackMsg{
Parse: "full",
Username: username(),
Text: scanner.Text(),
}

err = msg.Post(cfg.WebhookUrl)
if err != nil {
log.Fatalf("Post failed: %v", err)
err = msg.Post(cfg.WebhookUrl)
if err != nil {
log.Fatalf("Post failed: %v", err)
}
}
if err := scanner.Err(); err != nil {
log.Fatalf("Error reading: %v", err)
}
}

0 comments on commit 8ce046d

Please sign in to comment.