-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresponse.go
More file actions
28 lines (25 loc) · 763 Bytes
/
response.go
File metadata and controls
28 lines (25 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package persistentconn
import (
"encoding/json"
"fmt"
)
// Response represents the response sent back to the client
type Response struct {
isInit bool
StatusCode int `json:"status"`
Body string `json:"payload"`
}
// getRawData transforms the response to a payload that splunkd can decode
// splunkd protocol for response to init packet: "0\n" (empty byte with length 0) to indicate success
// splunkd protocl for response to data packet: <len_response_bytes>\n<response>
func (resp Response) getRawData() string {
if resp.isInit {
return "0\n"
}
respData, err := json.Marshal(&resp)
if err != nil {
respData = []byte("Failed to serialize response data")
}
rawData := fmt.Sprintf("%d\n%s", len(respData), respData)
return rawData
}