You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: fix removed opensearch.BuildRequest reference and sweep upgrade guides (#979)
* docs: fix removed opensearch.BuildRequest reference and sweep upgrade guides
The v4.7.0 migration section (and the raw-JSON usage guide) told readers to
forward a custom Request.GetRequest to opensearch.BuildRequest, but that helper
was removed in 4.7.0 -- the very release the section documents. Replace it with
a net/http-based before/after example (relative path; the transport prepends
the base URL).
A verification sweep of the remaining upgrade guides fixed:
- UPGRADING_V5.md: RawBody() comment wrongly listed error responses as nil.
- opensearchapi/UPGRADING_V4_TO_V5.md: SearchParams.Size is *int; the example
used a bare int literal that would not compile.
- UPGRADING_V3.md: InsecureSkipVerify did not exist in v2.3.0/v3.0.0; error
snippet had a variable-name mismatch and a missing return; Msearch/
MsearchTemplate casing in the v2.3.0 before-column.
- opensearchapi/UPGRADING_V3_TO_V4.md: scoped the CausedBy addition to v4.6.0.
Reported in #977.
Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
This change is invisible to almost all callers: the typed `Req` structs that the client consumes (e.g. `opensearchapi.SearchReq`, `opensearchapi.IndexReq`) already implement the new signature. Only code that defines a custom type satisfying `opensearch.Request` is affected. If you maintain such a type, add a `method string` parameter and forward it to your underlying `http.NewRequest` call (or `opensearch.BuildRequest`).
17
+
This change is invisible to almost all callers: the typed `Req` structs that the client consumes (e.g. `opensearchapi.SearchReq`, `opensearchapi.IndexReq`) already implement the new signature. Only code that defines a custom type satisfying `opensearch.Request` is affected.
18
+
19
+
If you maintain such a type, add a `method string` parameter and forward it to your request builder. The `opensearch.BuildRequest` helper that earlier v4 releases exposed for this purpose was **removed in 4.7.0**; construct the request with `net/http` directly instead.
20
+
21
+
```go
22
+
// Before (<= 4.6.0): method stored on the struct, built via the removed
23
+
// opensearch.BuildRequest helper (which set Content-Type for a non-nil body).
`opensearch.BuildRequest` also accepted `params map[string]string` and `headers http.Header` arguments. To preserve those, set them on the `*http.Request` after construction: encode params onto `req.URL.RawQuery` (via `url.Values`) and add headers to `req.Header`.
44
+
45
+
> The path must begin with a leading slash (e.g. `r.path == "/_plugins/my_plugin/status"`). The transport builds the final URL by concatenating the base URL with the request path (`base + req.URL.Path` in `opensearchtransport.setReqURL`), not via `url.ResolveReference`, so a path without a leading slash produces a malformed URL.
For responses decoded by `opensearch.Execute`, the buffered bytes are also available without consuming the body reader via the `RawBody() []byte` method (useful for inspection or comparison testing):
215
215
216
216
```go
217
-
raw:= resp.RawBody() // nil for streamed or error responses; read resp.Body directly there
217
+
raw:= resp.RawBody() // nil for streamed responses (Client.Stream); read resp.Body directly there
218
218
```
219
219
220
220
## `signer/aws` removed in favor of `signer/awsv2`
Copy file name to clipboardExpand all lines: opensearchapi/UPGRADING_V3_TO_V4.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,15 +29,15 @@ Files behind custom build tags (`//go:build <tag>`) are loaded under the default
29
29
30
30
In v3 the API error types lived in `opensearchapi` (`opensearchapi/error.go`). In v4 they moved to the root `opensearch` package and were redesigned. Update the imports and package qualifiers by hand:
The v3 detailed-error type `opensearchapi.Error{Err Err; Status int}` is now `opensearch.StructError`; the v4 `opensearch.Error` is a different, simpler type. Re-point type switches and assertions that decoded the detailed error to `opensearch.StructError`. `opensearch.Err`gains an optional `CausedBy *CausedBy` field for nested causes; existing field access is unaffected.
The v3 detailed-error type `opensearchapi.Error{Err Err; Status int}` is now `opensearch.StructError`; the v4 `opensearch.Error` is a different, simpler type. Re-point type switches and assertions that decoded the detailed error to `opensearch.StructError`. In a later v4 release (`v4.6.0`), `opensearch.Err`gained an optional `CausedBy *CausedBy` field for nested causes; existing field access is unaffected.
Pointer-typed `Params` lets callers pass `nil` when no parameters are needed and keeps the struct cheap to copy.
74
+
Pointer-typed `Params` lets callers pass `nil` when no parameters are needed and keeps the struct cheap to copy. `Size` itself has been `*int` since v4.0.0 and is unchanged here -- only the surrounding `Params` value became a pointer.
75
+
76
+
> On Go 1.26+ you can write `new(20)` in place of `opensearch.ToPointer(20)`; both produce a `*int`.
0 commit comments