(ctx context.Context, apiUrl string, data interface{})
| 267 | } |
| 268 | |
| 269 | func makePingPostReq(ctx context.Context, apiUrl string, data interface{}) (*http.Request, error) { |
| 270 | endpoint := GetPingEndpoint() |
| 271 | if endpoint == "" { |
| 272 | return nil, errors.New("wcloud ping endpoint not set") |
| 273 | } |
| 274 | var dataReader io.Reader |
| 275 | if data != nil { |
| 276 | byteArr, err := json.Marshal(data) |
| 277 | if err != nil { |
| 278 | return nil, fmt.Errorf("error marshaling json for %s request: %v", apiUrl, err) |
| 279 | } |
| 280 | dataReader = bytes.NewReader(byteArr) |
| 281 | } |
| 282 | fullUrl := endpoint + apiUrl |
| 283 | req, err := http.NewRequestWithContext(ctx, "POST", fullUrl, dataReader) |
| 284 | if err != nil { |
| 285 | return nil, fmt.Errorf("error creating %s request: %v", apiUrl, err) |
| 286 | } |
| 287 | req.Header.Set("Content-Type", "application/json") |
| 288 | req.Header.Set("X-PromptAPIVersion", strconv.Itoa(APIVersion)) |
| 289 | req.Close = true |
| 290 | return req, nil |
| 291 | } |
| 292 | |
| 293 | type PingInputType struct { |
| 294 | ClientId string `json:"clientid"` |
no test coverage detected