Skip to content

Commit 8f8512d

Browse files
committed
Update SDK to version 1.0.10
1 parent fbc5af5 commit 8f8512d

23 files changed

+852
-2249
lines changed

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ go get github.com/flexprice/go-sdk
1010

1111
## Usage
1212

13+
### Basic API Usage
14+
1315
```go
1416
package main
1517

@@ -121,12 +123,97 @@ func main() {
121123
}
122124
```
123125

126+
### Async Client Usage
127+
128+
The FlexPrice Go SDK includes an asynchronous client for more efficient event tracking, especially for high-volume applications:
129+
130+
```go
131+
func RunAsyncSample(client *flexprice.APIClient) {
132+
// Create an AsyncClient with debug enabled
133+
asyncConfig := flexprice.DefaultAsyncConfig()
134+
asyncConfig.Debug = true
135+
asyncClient := client.NewAsyncClientWithConfig(asyncConfig)
136+
137+
// Example 1: Simple event
138+
err := asyncClient.Enqueue(
139+
"api_request",
140+
"customer-123",
141+
map[string]interface{}{
142+
"path": "/api/resource",
143+
"method": "GET",
144+
"status": "200",
145+
"response_time_ms": 150,
146+
},
147+
)
148+
if err != nil {
149+
log.Fatalf("Failed to enqueue event: %v", err)
150+
}
151+
fmt.Println("Enqueued simple event")
152+
153+
// Example 2: Event with additional options
154+
err = asyncClient.EnqueueWithOptions(flexprice.EventOptions{
155+
EventName: "file_upload",
156+
ExternalCustomerID: "customer-123",
157+
CustomerID: "cust_456", // Optional internal FlexPrice ID
158+
EventID: "event_789", // Custom event ID
159+
Properties: map[string]interface{}{
160+
"file_size_bytes": 1048576,
161+
"file_type": "image/jpeg",
162+
"storage_bucket": "user_uploads",
163+
},
164+
Source: "upload_service",
165+
Timestamp: time.Now().Format(time.RFC3339),
166+
})
167+
if err != nil {
168+
log.Fatalf("Failed to enqueue event: %v", err)
169+
}
170+
fmt.Println("Enqueued event with custom options")
171+
172+
// Example 3: Batch multiple events
173+
for i := 0; i < 10; i++ {
174+
err = asyncClient.Enqueue(
175+
"batch_example",
176+
fmt.Sprintf("customer-%d", i),
177+
map[string]interface{}{
178+
"index": i,
179+
"batch": "demo",
180+
},
181+
)
182+
if err != nil {
183+
log.Fatalf("Failed to enqueue batch event: %v", err)
184+
}
185+
}
186+
fmt.Println("Enqueued 10 batch events")
187+
188+
// Wait for a moment to let the API requests complete
189+
fmt.Println("Waiting for events to be processed...")
190+
time.Sleep(time.Second * 5)
191+
192+
// Explicitly close the client - this will flush any remaining events
193+
fmt.Println("Closing client...")
194+
asyncClient.Close()
195+
196+
fmt.Println("Example completed successfully!")
197+
}
198+
```
199+
200+
## Async Client Benefits
201+
202+
The async client provides several advantages:
203+
204+
1. **Efficient Batching**: Events are automatically batched for more efficient API usage
205+
2. **Background Processing**: Events are sent asynchronously, not blocking your application
206+
3. **Auto-Generated IDs**: EventIDs are automatically generated if not provided
207+
4. **Rich Property Types**: Properties support various types (numbers, booleans, etc.)
208+
5. **Detailed Logging**: Enable debug mode for comprehensive logging
209+
124210
## Features
125211

126212
- Complete API coverage
127213
- Type-safe client
128214
- Detailed documentation
129215
- Error handling
216+
- Batch processing for high-volume applications
130217

131218
## Documentation
132219

0 commit comments

Comments
 (0)