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