Skip to content

Commit

Permalink
update package name
Browse files Browse the repository at this point in the history
  • Loading branch information
robarchibald committed Nov 19, 2021
1 parent 94f21d2 commit 778d647
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Sling [![Build Status](https://github.com/dghubble/sling/workflows/test/badge.svg)](https://github.com/dghubble/oauth1/actions?query=workflow%3Atest+branch%3Amaster) [![Coverage](https://gocover.io/_badge/github.com/dghubble/sling)](https://gocover.io/github.com/dghubble/sling) [![GoDoc](https://godoc.org/github.com/dghubble/sling?status.svg)](https://godoc.org/github.com/dghubble/sling)
# Sling [![Build Status](https://github.com/mypricehealth/sling/workflows/test/badge.svg)](https://github.com/mypricehealth/oauth1/actions?query=workflow%3Atest+branch%3Amaster) [![Coverage](https://gocover.io/_badge/github.com/mypricehealth/sling)](https://gocover.io/github.com/mypricehealth/sling) [![GoDoc](https://godoc.org/github.com/mypricehealth/sling?status.svg)](https://godoc.org/github.com/mypricehealth/sling)

<img align="right" src="https://storage.googleapis.com/dghubble/small-gopher-with-sling.png">

Sling is a Go HTTP client library for creating and sending API requests.

Slings store HTTP Request properties to simplify sending requests and decoding responses. Check [usage](#usage) or the [examples](examples) to learn how to compose a Sling into your API client.

This is a fork of the package by `dghubble` and adds some additional features not currently supported in the original (see the "mypricehealth Exclusive Features" section). There is a PR in for the `dghubble` package with these additional features (https://github.com/dghubble/sling/pull/71), so this package will be retired if/when that PR gets merged.

### Features

* Method Setters: Get/Post/Put/Patch/Delete/Head
Expand All @@ -15,15 +17,31 @@ Slings store HTTP Request properties to simplify sending requests and decoding r
* Encode a form or JSON into the Request Body
* Receive JSON success or failure responses


### mypricehealth Exclusive Features

* The ability to set a body form with `url.Values` in addition to using a struct and `go-query`. While I love the `goquery` mechanism, there are times, I just want to go straight to `url.Values` directly.
* The ability to set all headers or add to all headers at once. Sometimes it's just easier to pass it all in at once
* The ability to set the http method directly
* The ability to add queryString parameters using `url.Values` in addition to `goquery`
* The ability to run the final request with a `Context`

### mypricehealth Bug Fixes
* Return an error string if no error struct is supplied and an error is returned by the http request (the error is swallowed in the `dghubble` package)

### Fork motivation

This fork enables a nice `Do` method API packages with a `Context`, access to all http methods, and flexibility for getting data into the query string or body.

## Install

```
go get github.com/dghubble/sling
go get github.com/mypricehealth/sling
```

## Documentation

Read [GoDoc](https://godoc.org/github.com/dghubble/sling)
Read [GoDoc](https://godoc.org/github.com/mypricehealth/sling)

## Usage

Expand Down Expand Up @@ -267,7 +285,7 @@ func (s *IssueService) ListByRepo(owner, repo string, params *IssueListParams) (
}
```

## Example APIs using Sling
## Example APIs using `dghubble` Sling

* Digits [dghubble/go-digits](https://github.com/dghubble/go-digits)
* GoSquared [drinkin/go-gosquared](https://github.com/drinkin/go-gosquared)
Expand All @@ -279,6 +297,10 @@ func (s *IssueService) ListByRepo(owner, repo string, params *IssueListParams) (

Create a Pull Request to add a link to your own API.

## Example APIs using `mypricehealth` Sling

* Geocodio [mypricehealth/geocodio](https://github.com/mypricehealth/geocodio)

## Motivation

Many client libraries follow the lead of [google/go-github](https://github.com/google/go-github) (our inspiration!), but do so by reimplementing logic common to all clients.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/dghubble/sling
module github.com/mypricehealth/sling

go 1.16

Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
2 changes: 1 addition & 1 deletion sling.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func decodeResponse(resp *http.Response, decoder ResponseDecoder, successV, fail
}
var buf bytes.Buffer
buf.ReadFrom(resp.Body)
return fmt.Errorf("error %d - %s: body: %s", resp.StatusCode, resp.Status, buf.String())
return fmt.Errorf("error %s: body: %s", resp.Status, buf.String())
}
return nil
}
4 changes: 2 additions & 2 deletions sling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,8 @@ func TestDo_onFailureWithNilValue(t *testing.T) {
model := new(FakeModel)
resp, err := sling.Do(req, model, nil)

if err != nil {
t.Errorf("expected nil, got %v", err)
if err == nil {
t.Errorf("expected error, got nil")
}
if resp.StatusCode != 420 {
t.Errorf("expected %d, got %d", 420, resp.StatusCode)
Expand Down

0 comments on commit 778d647

Please sign in to comment.