Skip to content

Commit

Permalink
Updated func descriptions and fixed url to correct branch name
Browse files Browse the repository at this point in the history
  • Loading branch information
davesavic committed Jan 7, 2024
1 parent 4819b09 commit 5fdfa86
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![test](https://github.com/davesavic/clink/workflows/test/badge.svg)](https://github.com/davesavic/clink/actions?query=workflow%3Atest)
[![coverage](https://coveralls.io/repos/github/davesavic/clink/badge.svg?branch=main)](https://coveralls.io/github/davesavic/clink?branch=main)
[![coverage](https://coveralls.io/repos/github/davesavic/clink/badge.svg?branch=master)](https://coveralls.io/github/davesavic/clink?branch=master)
[![goreportcard](https://goreportcard.com/badge/github.com/davesavic/clink)](https://goreportcard.com/report/github.com/davesavic/clink)
[![gopkg](https://pkg.go.dev/badge/github.com/davesavic/clink.svg)](https://pkg.go.dev/github.com/davesavic/clink)
[![license](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/davesavic/clink/blob/master/LICENSE)
Expand Down
12 changes: 12 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"golang.org/x/time/rate"
)

// Client is a wrapper around http.Client with additional functionality.
type Client struct {
HttpClient *http.Client
Headers map[string]string
Expand All @@ -19,6 +20,7 @@ type Client struct {
ShouldRetryFunc func(*http.Request, *http.Response, error) bool
}

// NewClient creates a new client with the given options.
func NewClient(opts ...Option) *Client {
c := defaultClient()

Expand All @@ -36,6 +38,9 @@ func defaultClient() *Client {
}
}

// Do sends the given request and returns the response.
// If the request is rate limited, the client will wait for the rate limiter to allow the request.
// If the request fails, the client will retry the request the number of times specified by MaxRetries.
func (c *Client) Do(req *http.Request) (*http.Response, error) {
for key, value := range c.Headers {
req.Header.Set(key, value)
Expand Down Expand Up @@ -70,6 +75,7 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
return resp, nil
}

// Head sends a HEAD request to the given URL.
func (c *Client) Head(url string) (*http.Response, error) {
req, err := http.NewRequest(http.MethodHead, url, nil)
if err != nil {
Expand All @@ -78,6 +84,7 @@ func (c *Client) Head(url string) (*http.Response, error) {
return c.Do(req)
}

// Get sends a GET request to the given URL.
func (c *Client) Options(url string) (*http.Response, error) {
req, err := http.NewRequest(http.MethodOptions, url, nil)
if err != nil {
Expand All @@ -86,6 +93,7 @@ func (c *Client) Options(url string) (*http.Response, error) {
return c.Do(req)
}

// Get sends a GET request to the given URL.
func (c *Client) Get(url string) (*http.Response, error) {
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
Expand All @@ -94,6 +102,7 @@ func (c *Client) Get(url string) (*http.Response, error) {
return c.Do(req)
}

// Post sends a POST request to the given URL with the given body.
func (c *Client) Post(url string, body io.Reader) (*http.Response, error) {
req, err := http.NewRequest(http.MethodPost, url, body)
if err != nil {
Expand All @@ -102,6 +111,7 @@ func (c *Client) Post(url string, body io.Reader) (*http.Response, error) {
return c.Do(req)
}

// Put sends a PUT request to the given URL.
func (c *Client) Put(url string, body io.Reader) (*http.Response, error) {
req, err := http.NewRequest(http.MethodPut, url, body)
if err != nil {
Expand All @@ -110,6 +120,7 @@ func (c *Client) Put(url string, body io.Reader) (*http.Response, error) {
return c.Do(req)
}

// Patch sends a PATCH request to the given URL.
func (c *Client) Patch(url string, body io.Reader) (*http.Response, error) {
req, err := http.NewRequest(http.MethodPatch, url, body)
if err != nil {
Expand All @@ -118,6 +129,7 @@ func (c *Client) Patch(url string, body io.Reader) (*http.Response, error) {
return c.Do(req)
}

// Delete sends a DELETE request to the given URL.
func (c *Client) Delete(url string) (*http.Response, error) {
req, err := http.NewRequest(http.MethodDelete, url, nil)
if err != nil {
Expand Down
109 changes: 65 additions & 44 deletions coverage.out
Original file line number Diff line number Diff line change
@@ -1,44 +1,65 @@
mode: set
github.com/davesavic/clink/client.go:21.40,24.27 2 1
github.com/davesavic/clink/client.go:24.27,26.3 1 1
github.com/davesavic/clink/client.go:28.2,28.10 1 1
github.com/davesavic/clink/client.go:31.30,36.2 1 1
github.com/davesavic/clink/client.go:38.64,39.36 1 1
github.com/davesavic/clink/client.go:39.36,41.3 1 1
github.com/davesavic/clink/client.go:43.2,43.26 1 1
github.com/davesavic/clink/client.go:43.26,44.59 1 1
github.com/davesavic/clink/client.go:44.59,46.4 1 0
github.com/davesavic/clink/client.go:49.2,52.55 3 1
github.com/davesavic/clink/client.go:52.55,55.69 2 1
github.com/davesavic/clink/client.go:55.69,56.9 1 1
github.com/davesavic/clink/client.go:59.3,59.29 1 1
github.com/davesavic/clink/client.go:59.29,62.4 1 1
github.com/davesavic/clink/client.go:65.2,65.16 1 1
github.com/davesavic/clink/client.go:65.16,67.3 1 0
github.com/davesavic/clink/client.go:69.2,69.18 1 1
github.com/davesavic/clink/client.go:75.45,76.25 1 1
github.com/davesavic/clink/client.go:76.25,78.3 1 1
github.com/davesavic/clink/client.go:82.43,83.25 1 1
github.com/davesavic/clink/client.go:83.25,85.3 1 1
github.com/davesavic/clink/client.go:89.52,90.25 1 1
github.com/davesavic/clink/client.go:90.25,91.35 1 1
github.com/davesavic/clink/client.go:91.35,93.4 1 1
github.com/davesavic/clink/client.go:98.36,99.25 1 1
github.com/davesavic/clink/client.go:99.25,102.3 2 1
github.com/davesavic/clink/client.go:106.54,107.25 1 1
github.com/davesavic/clink/client.go:107.25,111.3 3 1
github.com/davesavic/clink/client.go:115.42,116.25 1 1
github.com/davesavic/clink/client.go:116.25,118.3 1 1
github.com/davesavic/clink/client.go:122.38,123.25 1 1
github.com/davesavic/clink/client.go:123.25,125.3 1 1
github.com/davesavic/clink/client.go:129.95,130.25 1 1
github.com/davesavic/clink/client.go:130.25,133.3 2 1
github.com/davesavic/clink/client.go:137.70,138.21 1 1
github.com/davesavic/clink/client.go:138.21,140.3 1 1
github.com/davesavic/clink/client.go:142.2,142.26 1 1
github.com/davesavic/clink/client.go:142.26,144.3 1 1
github.com/davesavic/clink/client.go:146.2,146.33 1 1
github.com/davesavic/clink/client.go:146.33,148.3 1 1
github.com/davesavic/clink/client.go:150.2,150.70 1 1
github.com/davesavic/clink/client.go:150.70,152.3 1 1
github.com/davesavic/clink/client.go:154.2,154.12 1 1
mode: count
github.com/davesavic/clink/client.go:24.40,27.27 2 24
github.com/davesavic/clink/client.go:27.27,29.3 1 28
github.com/davesavic/clink/client.go:31.2,31.10 1 24
github.com/davesavic/clink/client.go:34.30,39.2 1 24
github.com/davesavic/clink/client.go:44.64,45.36 1 16
github.com/davesavic/clink/client.go:45.36,47.3 1 2
github.com/davesavic/clink/client.go:49.2,49.26 1 16
github.com/davesavic/clink/client.go:49.26,50.59 1 2
github.com/davesavic/clink/client.go:50.59,52.4 1 0
github.com/davesavic/clink/client.go:55.2,58.55 3 16
github.com/davesavic/clink/client.go:58.55,61.69 2 19
github.com/davesavic/clink/client.go:61.69,62.9 1 1
github.com/davesavic/clink/client.go:65.3,65.29 1 18
github.com/davesavic/clink/client.go:65.29,68.4 1 3
github.com/davesavic/clink/client.go:71.2,71.16 1 16
github.com/davesavic/clink/client.go:71.16,73.3 1 0
github.com/davesavic/clink/client.go:75.2,75.18 1 16
github.com/davesavic/clink/client.go:79.59,81.16 2 1
github.com/davesavic/clink/client.go:81.16,83.3 1 0
github.com/davesavic/clink/client.go:84.2,84.18 1 1
github.com/davesavic/clink/client.go:88.62,90.16 2 1
github.com/davesavic/clink/client.go:90.16,92.3 1 0
github.com/davesavic/clink/client.go:93.2,93.18 1 1
github.com/davesavic/clink/client.go:97.58,99.16 2 1
github.com/davesavic/clink/client.go:99.16,101.3 1 0
github.com/davesavic/clink/client.go:102.2,102.18 1 1
github.com/davesavic/clink/client.go:106.75,108.16 2 1
github.com/davesavic/clink/client.go:108.16,110.3 1 0
github.com/davesavic/clink/client.go:111.2,111.18 1 1
github.com/davesavic/clink/client.go:115.74,117.16 2 1
github.com/davesavic/clink/client.go:117.16,119.3 1 0
github.com/davesavic/clink/client.go:120.2,120.18 1 1
github.com/davesavic/clink/client.go:124.76,126.16 2 1
github.com/davesavic/clink/client.go:126.16,128.3 1 0
github.com/davesavic/clink/client.go:129.2,129.18 1 1
github.com/davesavic/clink/client.go:133.61,135.16 2 1
github.com/davesavic/clink/client.go:135.16,137.3 1 0
github.com/davesavic/clink/client.go:138.2,138.18 1 1
github.com/davesavic/clink/client.go:144.45,145.25 1 16
github.com/davesavic/clink/client.go:145.25,147.3 1 16
github.com/davesavic/clink/client.go:151.43,152.25 1 2
github.com/davesavic/clink/client.go:152.25,154.3 1 2
github.com/davesavic/clink/client.go:158.52,159.25 1 2
github.com/davesavic/clink/client.go:159.25,160.35 1 2
github.com/davesavic/clink/client.go:160.35,162.4 1 2
github.com/davesavic/clink/client.go:167.36,168.25 1 2
github.com/davesavic/clink/client.go:168.25,171.3 2 2
github.com/davesavic/clink/client.go:175.54,176.25 1 1
github.com/davesavic/clink/client.go:176.25,180.3 3 1
github.com/davesavic/clink/client.go:184.42,185.25 1 1
github.com/davesavic/clink/client.go:185.25,187.3 1 1
github.com/davesavic/clink/client.go:191.38,192.25 1 1
github.com/davesavic/clink/client.go:192.25,194.3 1 1
github.com/davesavic/clink/client.go:198.95,199.25 1 3
github.com/davesavic/clink/client.go:199.25,202.3 2 3
github.com/davesavic/clink/client.go:206.70,207.21 1 7
github.com/davesavic/clink/client.go:207.21,209.3 1 1
github.com/davesavic/clink/client.go:211.2,211.26 1 6
github.com/davesavic/clink/client.go:211.26,213.3 1 1
github.com/davesavic/clink/client.go:215.2,215.33 1 5
github.com/davesavic/clink/client.go:215.33,217.3 1 5
github.com/davesavic/clink/client.go:219.2,219.70 1 5
github.com/davesavic/clink/client.go:219.70,221.3 1 1
github.com/davesavic/clink/client.go:223.2,223.12 1 4

0 comments on commit 5fdfa86

Please sign in to comment.