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
Copy file name to clipboardExpand all lines: docs/doc_5_best_practices.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,12 +33,12 @@ if test != ""
33
33
In the Atlas Go SDK, the `*time.Time` type represents date fields for handling time-related data.
34
34
When you compare values based on `time.Time`, either never compare pointers directly or do the following:
35
35
36
-
1. Avoid using direct comparison operators (e.g., `myStruct.MyDateField == ""`) to check for equality. Comparing pointers directly will check if they refer to the same memory address rather than comparing the actual date values. Since each `time.Time` instance is allocated in different memory locations, direct comparisons might yield unexpected results.
36
+
- Avoid using direct comparison operators (e.g., `myStruct.MyDateField == ""`) to check for equality. Comparing pointers directly will check if they refer to the same memory address rather than comparing the actual date values. Since each `time.Time` instance is allocated in different memory locations, direct comparisons might yield unexpected results.
37
37
38
-
2. Use the `Has` function to check non-nil pointers:
38
+
- Use the `Has` function to check non-nil pointers:
39
39
The SDK provides a dedicated `HasFieldName` or `GetFieldName` function for each model to check if a `time.Time` pointer is non-nil before accessing its value. Always use this function to ensure that the pointer is valid before you perform any operations.
40
40
41
-
3. Use `time.Time` methods to compare date values:
41
+
- Use `time.Time` methods to compare date values:
42
42
When you have confirmed that the `time.Time pointer` is non-nil, you can safely use `time.Time` methods to compare the actual date values. Commonly used methods for comparison include `Before`, `After`, and `Equal`:
43
43
```go
44
44
if !sdkModel.HasSomeDateField() {
@@ -79,7 +79,7 @@ type Data struct {
79
79
80
80
The following scenarios use pointers with arrays:
81
81
82
-
1. Update a request containing an empty array (resetting the field values):
82
+
- Update a request containing an empty array (resetting the field values):
83
83
84
84
If you explicitly set a struct property to an empty array, the SDK will send an empty array request to the Atlas API.
85
85
@@ -90,7 +90,7 @@ data := Data{
90
90
}
91
91
```
92
92
93
-
2. Update a request without updating the array field:
93
+
- Update a request without updating the array field:
94
94
95
95
When performing an update operation, we recommend that you don't set the struct property.
96
96
@@ -113,7 +113,7 @@ In the Atlas Go SDK, the `io.ReadCloser` type is used to return binary data usin
113
113
114
114
- Call the `.Close()` function after reading the data
115
115
116
-
Note: see example in [examples/download/downloadLogs.go](../examples/download/downloadLogs.go)
116
+
Note: see example in [examples/download/downloadLogs.go](https://github.com/mongodb/atlas-sdk-go/blob/main/examples/download/downloadLogs.go)
0 commit comments