Skip to content

Commit

Permalink
CLOUDP-213199 Atlas Go SDK docs changes for binary responses (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmenezes authored Dec 5, 2023
1 parent 60a45f7 commit 3744079
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 6 additions & 4 deletions docs/doc_5_best_practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ When you have confirmed that the `time.Time pointer` is non-nil, you can safely

## Working with Binary Responses

In the Atlas Go SDK, the `io.ReadCloser` type is used to return binary data from APIs.
In the Atlas Go SDK, the `io.ReadCloser` type is used to return binary data using the APIs.

1. Use `io.Copy` if the intention is to store on a file or pass through another steam
- Use `io.Copy` to store on a file or pass through another steam.

2. Use `io.ReadAll` if the intention is to read all bytes in memory
- Use `io.ReadAll` to read all bytes in memory.

3. Call the `.Close()` function after done reading the data
- Call the `.Close()` function after reading the data

Note: see example in [examples/download/downloadLogs.go](../examples/download/downloadLogs.go)

## Use Method for Creating Models

Expand Down
3 changes: 1 addition & 2 deletions examples/download/downloadLogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func main() {
if projects.GetTotalCount() == 0 {
log.Fatal("account should have at least single project")
}
var out io.Writer = os.Stdout
projectId := projects.GetResults()[0].GetId()

// -- 2. Get first Process
Expand All @@ -61,6 +60,6 @@ func main() {
defer func() {
_ = logs.Close()
}()
_, err = io.Copy(out, logs)
_, err = io.Copy(os.Stdout, logs)
examples.HandleErr(err, nil)
}

0 comments on commit 3744079

Please sign in to comment.