aboutsummaryrefslogtreecommitdiff
path: root/exec_response.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-11-27 19:11:56 +0700
committerShulhan <ms@kilabit.info>2023-12-01 13:17:30 +0700
commit22ad970d426c07bb36c3f71856ba16183377a5f4 (patch)
tree5ecddacad15fad7d3d5d38fe3ab9bbbde2e63395 /exec_response.go
parent115adf2ed71b602204cd9fedb0e046e731aa7e38 (diff)
downloadawwan-22ad970d426c07bb36c3f71856ba16183377a5f4.tar.xz
all: handle reconnecting when streaming execution
In "/awwan/api/execute/tail" SSE endpoint, in order for client to be able to reconnect and start streaming from the last know output, we need to send the ID for each message that we send. The ID is the index of Output in slice. If client does not send Last-Event-ID, we send all Output from beginning, otherwise, we send only message start from index in Last-Event-ID.
Diffstat (limited to 'exec_response.go')
-rw-r--r--exec_response.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/exec_response.go b/exec_response.go
index 409e5db..9665187 100644
--- a/exec_response.go
+++ b/exec_response.go
@@ -71,6 +71,11 @@ func (execRes *ExecResponse) Write(out []byte) (n int, err error) {
return 0, nil
}
+ var outlen = len(out)
+ if out[outlen-1] == '\n' {
+ out = out[:outlen-1]
+ }
+
var (
lines = bytes.Split(out, []byte{'\n'})