Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #22 from engvik/feature/http-timeout
Browse files Browse the repository at this point in the history
feature: configurable http timeout
  • Loading branch information
engvik authored Feb 1, 2021
2 parents 3c8abf6 + ed35f93 commit 191d93e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ Usage example:

`sbanken a r --id checking`

### HTTP Timeout

Number of seconds to wait before timing out http requests.

Global option: `--http-timeout value`
Config option: `http-timeout: value`
Default: `30`

## Usage

```
Expand Down Expand Up @@ -146,6 +154,7 @@ GLOBAL OPTIONS:
--customer-id value, --cuid value customer id [$SBANKEN_CUSTOMER_ID]
--style value set output style
--colors add colors to values (default: false)
--http-timeout value timeout in seconds (default: 30)
--config value, -c value path to YAML config [$SBANKEN_CONFIG]
--help, -h show help (default: false)
--version, -v print the version (default: false)
Expand Down
5 changes: 5 additions & 0 deletions internal/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func getGlobalFlags() []cli.Flag {
Name: "colors",
Usage: "add colors to values",
}),
altsrc.NewIntFlag(&cli.IntFlag{
Name: "http-timeout",
Usage: "timeout in seconds",
Value: 30,
}),
&cli.StringFlag{
Name: "config",
Usage: "path to YAML config",
Expand Down
9 changes: 8 additions & 1 deletion internal/sbanken/sbanken.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"context"
"fmt"
"io"
"net/http"
"os"
"regexp"
"strings"
"time"

"github.com/engvik/sbanken-go"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -75,7 +77,12 @@ func (c *Connection) ConnectClient(ctx context.Context, cliCtx *cli.Context, ver
CustomerID: cliCtx.String("customer-id"),
UserAgent: fmt.Sprintf("sbanken-cli/%s (github.com/engvik/sbanken-cli)", version),
}
sClient, err := sbanken.NewClient(ctx, cfg, nil)

httpClient := &http.Client{
Timeout: time.Second * time.Duration(cliCtx.Int("http-timeout")),
}

sClient, err := sbanken.NewClient(ctx, cfg, httpClient)
if err != nil {
return err
}
Expand Down

0 comments on commit 191d93e

Please sign in to comment.