|
1 | 1 | package plugin
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "bytes" |
5 | 4 | "context"
|
6 | 5 | "encoding/base64"
|
7 | 6 | "encoding/json"
|
| 7 | + "fmt" |
8 | 8 | "net/http"
|
9 | 9 |
|
10 | 10 | tf "github.com/galeone/tensorflow/tensorflow/go"
|
@@ -100,20 +100,11 @@ func (p *Plugin) OnTrafficFromClient(
|
100 | 100 | return req, nil
|
101 | 101 | }
|
102 | 102 |
|
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"])) |
107 | 106 | 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) |
117 | 108 | return req, nil
|
118 | 109 | }
|
119 | 110 |
|
@@ -174,14 +165,15 @@ func (p *Plugin) OnTrafficFromClient(
|
174 | 165 | readyForQuery := &pgproto3.ReadyForQuery{TxStatus: 'I'}
|
175 | 166 |
|
176 | 167 | // Create a buffer to write the response to.
|
177 |
| - buf := errResp.Encode(nil) |
| 168 | + response := errResp.Encode(nil) |
178 | 169 | // TODO: Decide whether to terminate the connection.
|
179 |
| - buf = readyForQuery.Encode(buf) |
| 170 | + response = readyForQuery.Encode(response) |
180 | 171 |
|
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 |
185 | 177 | }
|
186 | 178 |
|
187 | 179 | return req, nil
|
|
0 commit comments