Skip to content

Commit

Permalink
Merge pull request #4 from percipia/cdata
Browse files Browse the repository at this point in the history
Send AppArgs for Set/Export/Push via the body of the SendMessage execute command
  • Loading branch information
winsock authored Jan 15, 2021
2 parents f91070b + a9ca4a0 commit 4b56517
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ eslgo was written from the ground up in idiomatic Go for use in our production p
go get github.com/percipia/eslgo
```
```
github.com/percipia/eslgo v1.3.1
github.com/percipia/eslgo v1.3.2
```

## Overview
Expand Down
28 changes: 15 additions & 13 deletions command/call/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ import (
)

type Execute struct {
UUID string
AppName string
AppArgs string
AppUUID string
Loops int
Sync bool
SyncPri bool
UUID string
AppName string
AppArgs string
AppUUID string
Loops int
Sync bool
SyncPri bool
ForceBody bool
}

// Helper to call Execute with Set since it is commonly used
Expand All @@ -44,11 +45,12 @@ type Push Set

func (s Set) buildMessage(app string) string {
e := Execute{
UUID: s.UUID,
AppName: app,
AppArgs: fmt.Sprintf("%s=%s", s.Key, s.Value),
Sync: s.Sync,
SyncPri: s.SyncPri,
UUID: s.UUID,
AppName: app,
AppArgs: fmt.Sprintf("%s=%s", s.Key, s.Value),
Sync: s.Sync,
SyncPri: s.SyncPri,
ForceBody: true,
}
return e.BuildMessage()
}
Expand Down Expand Up @@ -84,7 +86,7 @@ func (e *Execute) BuildMessage() string {
}

// According to documentation that is the max header length
if len(e.AppArgs) > 2048 {
if len(e.AppArgs) > 2048 || e.ForceBody {
sendMsg.Headers.Set("content-type", "text/plain")
sendMsg.Headers.Set("content-length", strconv.Itoa(len(e.AppArgs)))
sendMsg.Body = e.AppArgs
Expand Down
21 changes: 15 additions & 6 deletions command/call/execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,28 @@ Execute-App-Name: playback
Loops: 1`, "\n", "\r\n")
TestSetMessage = strings.ReplaceAll(`sendmsg none
Call-Command: execute
Execute-App-Arg: hello=world
Content-Length: 11
Content-Type: text/plain
Execute-App-Name: set
Loops: 1`, "\n", "\r\n")
Loops: 1
hello=world`, "\n", "\r\n")
TestExportMessage = strings.ReplaceAll(`sendmsg none
Call-Command: execute
Execute-App-Arg: hello=world
Content-Length: 11
Content-Type: text/plain
Execute-App-Name: export
Loops: 1`, "\n", "\r\n")
Loops: 1
hello=world`, "\n", "\r\n")
TestPushMessage = strings.ReplaceAll(`sendmsg none
Call-Command: execute
Execute-App-Arg: hello=world
Content-Length: 11
Content-Type: text/plain
Execute-App-Name: push
Loops: 1`, "\n", "\r\n")
Loops: 1
hello=world`, "\n", "\r\n")
)

func TestExecute_BuildMessage(t *testing.T) {
Expand Down

0 comments on commit 4b56517

Please sign in to comment.