Skip to content

Commit

Permalink
Add context-aware query function. (#8)
Browse files Browse the repository at this point in the history
I've noticed that sometimes the LotW API takes quite a while to respond
and being able to time out or cancel the queries by using a context
would be nice.
  • Loading branch information
jasonhancock authored Dec 12, 2020
1 parent 021c546 commit 6bf95b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cmd/lotw-qsl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package main
import (
"flag"
"fmt"
"os"

"github.com/antihax/optional"
"github.com/k0swe/lotw-qsl"
"os"
)

func main() {
Expand Down
12 changes: 8 additions & 4 deletions wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import (
"context"
)

/*
Query LotW and return an ADIF string with the results.
*/
// Query LotW and return an ADIF string with the results.
func Query(user string, pw string, opts *QueryOpts) (string, error) {
return QueryContext(context.Background(), user, pw, opts)
}

// QueryContext performs a context aware LotW query and returns an ADIF string
// with the results.
func QueryContext(ctx context.Context, user string, pw string, opts *QueryOpts) (string, error) {
config := NewConfiguration()
config.UserAgent = "k0swe/lotw-qsl 0.0.1"
client := NewAPIClient(config)
queryResp, _, err := client.DefaultApi.Query(context.TODO(), user, pw, 1, opts)
queryResp, _, err := client.DefaultApi.Query(ctx, user, pw, 1, opts)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 6bf95b6

Please sign in to comment.