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
**Requires at least Go 1.18-rc1 since we use generics on the internal API client**
9
+
We've designed this pkg to be familiar and ideomatic to any Go developer. Go get it the usual way:
10
+
11
+
> NOTE: Requires at least Go 1.18 since we use generics on the internal API client
10
12
11
13
```shell
12
14
go get github.com/airheartdev/duffel
@@ -22,7 +24,7 @@ The easiest way to get started, assuming you have a Duffel account set up and an
22
24
23
25
```go
24
26
// Create a new client:
25
-
client:= duffel.New(os.Getenv("DUFFEL_TOKEN"))
27
+
dfl:= duffel.New(os.Getenv("DUFFEL_TOKEN"))
26
28
```
27
29
28
30
For available methods, see:
@@ -48,8 +50,8 @@ total.String() // 100.00 USD
48
50
All requests that return more than one record will return an iterator. An Iterator automatically paginates results and respects rate limits, reducing the complexity of the overall programming model.
Each API method returns an error or an iterator that returns errors at each iteration. If an error is returned from Duffel, it will be of type `DuffelError` and expose more details on how to handle it.
82
84
83
85
```go
84
86
// Example error inspection after making an API call:
85
-
offer, err:=client.GetOffer(ctx, "off_123")
87
+
offer, err:=dfl.GetOffer(ctx, "off_123")
86
88
if err != nil {
89
+
// Simple error code check
90
+
if duffel.IsErrorCode(err, duffel.AirlineInternal) {
91
+
// Don't retry airline errors, contact support
92
+
}
93
+
94
+
// Access the DuffelError object to see more detail
87
95
ifderr, ok:= err.(*duffel.DuffelError); ok {
88
96
// derr.Errors[0].Type etc
89
97
// derr.IsCode(duffel.BadRequest)
@@ -93,6 +101,16 @@ if err != nil {
93
101
}
94
102
```
95
103
104
+
### `duffel.IsErrorCode(err, code)`
105
+
106
+
`IsErrorCode` is a concenience method to check if an error is a specific error code from Duffel.
107
+
This simplifies error handling branches without needing to type cast multiple times in your code.
108
+
109
+
### `duffel.IsErrorType(err, typ)`
110
+
111
+
`IsErrorType` is a concenience method to check if an error is a specific error type from Duffel.
112
+
This simplifies error handling branches without needing to type cast multiple times in your code.
113
+
96
114
You can also check the `derr.Retryable` field, which will be false if you need to contact Duffel support to resolve the issue, and should not be retried. Example, creating an order.
97
115
98
116
## Implementation status
@@ -118,7 +136,7 @@ To maintain simplicity and ease of use, this client library is hand-coded (inste
0 commit comments