Improved logging and stdin buffering
All checks were successful
Go / build (push) Successful in 20s

This commit is contained in:
Darius klein 2025-11-19 21:57:32 +01:00
parent bfc763c0c0
commit 5b763dc7b4

View File

@ -1,6 +1,7 @@
package main
import (
"bufio"
"context"
"encoding/json"
"fmt"
@ -60,13 +61,15 @@ func flags() []cli.Flag {
}
func action(context context.Context, c *cli.Command) error {
logger.Log("Notify starting")
sourcePath := c.String(constants.Source)
var input io.Reader
if sourcePath == "" {
fmt.Println("Reading from standard input (stdin)...")
input = os.Stdin
logger.Log("Reading from standard input (stdin)...")
input = bufio.NewReader(os.Stdin)
} else {
logger.Log("Reading from file (stdin)...")
file, err := common.ReadFile(sourcePath)
if err != nil {
return err
@ -133,13 +136,14 @@ func action(context context.Context, c *cli.Command) error {
}
func readInput(input io.Reader) (common.ActiveResponse, error) {
logger.Log("Parsing input")
var ar common.ActiveResponse
decoder := json.NewDecoder(input)
err := decoder.Decode(&ar)
if err != nil {
fmt.Fprintf(os.Stderr, "Error decoding JSON from stdin: %v\n", err)
logger.Log(fmt.Sprintf("Error decoding JSON from stdin: %v\n", err))
return ar, err
}