Skip to content

Commit 99de112

Browse files
committed
Return the entire req struct with extra fields
1 parent d258959 commit 99de112

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

plugin/plugin.go

+12-20
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package plugin
22

33
import (
4-
"bytes"
54
"context"
65
"encoding/base64"
76
"encoding/json"
7+
"fmt"
88
"net/http"
99

1010
tf "github.com/galeone/tensorflow/tensorflow/go"
@@ -100,20 +100,11 @@ func (p *Plugin) OnTrafficFromClient(
100100
return req, nil
101101
}
102102

103-
// Create the JSON body from the map.
104-
body, err := json.Marshal(map[string]interface{}{
105-
"query": queryMap["String"],
106-
})
103+
// Make an HTTP GET request to the tokenize service.
104+
resp, err := http.Get(
105+
fmt.Sprintf("http://localhost:5000/tokenize_and_sequence/%s", queryMap["String"]))
107106
if err != nil {
108-
p.Logger.Error("Failed to marshal query", "error", err)
109-
return req, nil
110-
}
111-
112-
// Make an HTTP POST request to the tokenize service.
113-
resp, err := http.Post(
114-
"http://localhost:5000/tokenize_and_sequence", "application/json", bytes.NewBuffer(body))
115-
if err != nil {
116-
p.Logger.Error("Failed to make POST request", "error", err)
107+
p.Logger.Error("Failed to make GET request", "error", err)
117108
return req, nil
118109
}
119110

@@ -174,14 +165,15 @@ func (p *Plugin) OnTrafficFromClient(
174165
readyForQuery := &pgproto3.ReadyForQuery{TxStatus: 'I'}
175166

176167
// Create a buffer to write the response to.
177-
buf := errResp.Encode(nil)
168+
response := errResp.Encode(nil)
178169
// TODO: Decide whether to terminate the connection.
179-
buf = readyForQuery.Encode(buf)
170+
response = readyForQuery.Encode(response)
180171

181-
return structpb.NewStruct(map[string]interface{}{
182-
"terminate": true,
183-
"response": buf,
184-
})
172+
// Create a response to send back to the client.
173+
req.Fields["response"] = structpb.NewStringValue(
174+
base64.StdEncoding.EncodeToString(response))
175+
req.Fields["terminate"] = structpb.NewBoolValue(true)
176+
return req, nil
185177
}
186178

187179
return req, nil

0 commit comments

Comments
 (0)