Fix(stdin-handler): Handle using reader instead of scanf

This commit is contained in:
2022-09-10 02:36:18 +08:00
parent 95ff3dabab
commit bcc99e523e

View File

@@ -1,6 +1,7 @@
package main package main
import ( import (
"bufio"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
@@ -43,17 +44,22 @@ func main() {
func handleStdIn(webhookFlag *bool, webhookURL *string) { func handleStdIn(webhookFlag *bool, webhookURL *string) {
for { for {
var err error
var currStr string var currStr string
_, err := fmt.Scanln(&currStr)
if err != nil {
return
}
// Handle string reader := bufio.NewReader(os.Stdin)
if *webhookFlag { for err == nil {
err = sendWebhook(&currStr, webhookURL) currStr, err = reader.ReadString('\n')
if err != nil { if err != nil {
log.Println(err) return
}
// Handle string
if *webhookFlag {
err = sendWebhook(&currStr, webhookURL)
if err != nil {
log.Println(err)
}
} }
} }
} }