WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 6d681eb

Browse files
authored
Merge pull request #18 from masl/change-http-client
Change http client
2 parents 2fd0202 + 3d01019 commit 6d681eb

File tree

6 files changed

+32
-51
lines changed

6 files changed

+32
-51
lines changed

.github/workflows/build.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ name: Build
22

33
on:
44
push:
5-
branches: [ main ]
6-
paths-ignore: '**.md'
5+
branches: [main]
6+
paths-ignore: ["**.md"]
77
pull_request:
8-
branches: [ main ]
9-
paths-ignore: '**.md'
8+
branches: [main]
9+
paths-ignore: ["**.md"]
1010

1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v3
1616

17-
- name: Set up Go
18-
uses: actions/setup-go@v2
19-
with:
20-
go-version: 1.16
17+
- name: Set up Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: '1.20.3'
2121

22-
- name: Build
23-
run: go build -v ./...
22+
- name: Build
23+
run: go build -v ./...
2424

25-
- name: Test
26-
run: go test -v ./...
25+
- name: Test
26+
run: go test -v ./...

client.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package frankfurtergo
33
import (
44
"encoding/json"
55
"fmt"
6+
"net/http"
67
"time"
7-
8-
"github.com/valyala/fasthttp"
98
)
109

1110
type ClientOptions struct {
@@ -14,7 +13,7 @@ type ClientOptions struct {
1413

1514
type Client struct {
1615
options *ClientOptions
17-
httpClient *fasthttp.Client
16+
httpClient *http.Client
1817
}
1918

2019
func New(options ...ClientOptions) *Client {
@@ -29,10 +28,8 @@ func New(options ...ClientOptions) *Client {
2928
}
3029

3130
return &Client{
32-
options: &opt,
33-
httpClient: &fasthttp.Client{
34-
Name: "frankfurtergo",
35-
},
31+
options: &opt,
32+
httpClient: &http.Client{},
3633
}
3734
}
3835

client_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ package frankfurtergo
22

33
import (
44
"testing"
5+
"time"
56
)
67

7-
func TestClient(*testing.T) {
8+
func TestClient(t *testing.T) {
89
s := New(ClientOptions{
910
Host: "api.frankfurter.app",
1011
})
1112

1213
s.FetchCurrencies()
1314
s.FetchLatest()
15+
t.Log(s.FetchLatest())
16+
t.Log(s.FetchSeries(time.Now().AddDate(0, 0, -3), time.Now(), RequestOptions{
17+
From: "USD",
18+
To: []string{"EUR", "PLN"},
19+
}))
1420
}

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module github.com/masl/frankfurtergo
22

3-
go 1.16
4-
5-
require github.com/valyala/fasthttp v1.37.0
3+
go 1.20

go.sum

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +0,0 @@
1-
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
2-
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
3-
github.com/klauspost/compress v1.15.0 h1:xqfchp4whNFxn5A4XFyyYtitiWI8Hy5EW59jEwcyL6U=
4-
github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
5-
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
6-
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
7-
github.com/valyala/fasthttp v1.37.0 h1:7WHCyI7EAkQMVmrfBhWTCOaeROb1aCBiTopx63LkMbE=
8-
github.com/valyala/fasthttp v1.37.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
9-
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
10-
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
11-
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
12-
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
13-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
14-
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
15-
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
16-
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
17-
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
18-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
19-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
20-
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
21-
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
22-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

request.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package frankfurtergo
33
import (
44
"errors"
55
"fmt"
6+
"io"
7+
"net/http"
68
"net/url"
79
"strconv"
810
"strings"
9-
10-
"github.com/valyala/fasthttp"
1111
)
1212

1313
type RequestOptions struct {
@@ -34,13 +34,15 @@ func (c *Client) jsonRequest(path string, options ...RequestOptions) (body []byt
3434
uri.RawQuery = queryValues.Encode()
3535
}
3636

37-
status, body, err := c.httpClient.Get(nil, uri.String())
37+
resp, err := c.httpClient.Get(uri.String())
3838
if err != nil {
3939
return
4040
}
41+
defer resp.Body.Close()
42+
body, err = io.ReadAll(resp.Body)
4143

42-
if status != fasthttp.StatusOK {
43-
return nil, errors.New(strconv.Itoa(status))
44+
if resp.StatusCode != http.StatusOK {
45+
return nil, errors.New(strconv.Itoa(resp.StatusCode))
4446
}
4547

4648
return

0 commit comments

Comments
 (0)