(ctx context.Context, apiUrl string, data interface{})
| 88 | } |
| 89 | |
| 90 | func makeAnonPostReq(ctx context.Context, apiUrl string, data interface{}) (*http.Request, error) { |
| 91 | endpoint := GetEndpoint() |
| 92 | if endpoint == "" { |
| 93 | return nil, errors.New("wcloud endpoint not set") |
| 94 | } |
| 95 | var dataReader io.Reader |
| 96 | if data != nil { |
| 97 | byteArr, err := json.Marshal(data) |
| 98 | if err != nil { |
| 99 | return nil, fmt.Errorf("error marshaling json for %s request: %v", apiUrl, err) |
| 100 | } |
| 101 | dataReader = bytes.NewReader(byteArr) |
| 102 | } |
| 103 | fullUrl := GetEndpoint() + apiUrl |
| 104 | req, err := http.NewRequestWithContext(ctx, "POST", fullUrl, dataReader) |
| 105 | if err != nil { |
| 106 | return nil, fmt.Errorf("error creating %s request: %v", apiUrl, err) |
| 107 | } |
| 108 | req.Header.Set("Content-Type", "application/json") |
| 109 | req.Header.Set("X-PromptAPIVersion", strconv.Itoa(APIVersion)) |
| 110 | req.Header.Set("X-PromptAPIUrl", apiUrl) |
| 111 | req.Close = true |
| 112 | return req, nil |
| 113 | } |
| 114 | |
| 115 | func doRequest(req *http.Request, outputObj interface{}, verbose bool) (*http.Response, error) { |
| 116 | apiUrl := req.Header.Get("X-PromptAPIUrl") |
no test coverage detected