Skip to content

Conversation

@eternal-flame-AD
Copy link
Member

This fixes #69.

Added a feature to split on null characters when reading from stdin. This way users can have one long-running gotify push and simply piping things to it.

@eternal-flame-AD eternal-flame-AD requested a review from a team as a code owner August 4, 2024 21:49
Signed-off-by: eternal-flame-AD <[email protected]>
read := bufio.NewReader(r)
for {
s, err := read.ReadString('\x00')
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified, if we always trim the suffix:

s, err := read.ReadString('\x00')

s = strings.TrimSuffix(s, "\x00")
if len(s) > 0 {
	output <- s
}
if errors.Is(err, io.EOF) {
	return
}
if err != nil {
	utils.Exit1With("read error", err)
}

cli.StringFlag{Name: "contentType", Usage: "The content type of the message. See https://gotify.net/docs/msgextras#client-display"},
cli.StringFlag{Name: "clickUrl", Usage: "An URL to open upon clicking the notification. See https://gotify.net/docs/msgextras#client-notification"},
cli.BoolFlag{Name: "disable-unescape-backslash", Usage: "Disable evaluating \\n and \\t (if set, \\n and \\t will be seen as a string)"},
cli.BoolFlag{Name: "no-split", Usage: "Do not split the message on null character when reading from stdin"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we invert this, so we don't changing existing behavior (reading stdin completely and pushing one message).

return locations[0]
}

for {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would I use this feature to simplify the journalctl call in #69?

I'm also not 100% sure about the actual use-case of feature, is there something not possible with the current cli feature set and xargs? I don't find the argument that we don't have to use xargs very strong for implementing this inside gotify/cli.

I think if someone doesn't have access to xargs then they probably don't use gotify/cli and instead use some "raw" http call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would I use this feature to simplify the journalctl call in #69?

journalctl -f -u sshd | awk 'NR % 5 == 0 { print "\0"} { print }' | gotify push

is there something not possible with the current cli feature set and xargs

makes sense, maybe I will just cherry pick the formatting bugs to a different PR and do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Feature: New option to push message every x lines(default 1)

3 participants