Import upstream version 1.4.1
Debian Janitor
1 year, 3 days ago
1 | 1 | on: |
2 | 2 | push: |
3 | 3 | branches: |
4 | - master | |
4 | - main | |
5 | 5 | pull_request: |
6 | branches: | |
7 | - master | |
8 | 6 | jobs: |
9 | 7 | build: |
10 | 8 | name: go |
12 | 10 | strategy: |
13 | 11 | fail-fast: false |
14 | 12 | matrix: |
15 | go: ['1.16', '1.17'] | |
13 | go: ['1.18', '1.19'] | |
16 | 14 | steps: |
17 | 15 | - name: setup |
18 | uses: actions/setup-go@v2 | |
16 | uses: actions/setup-go@v3 | |
19 | 17 | with: |
20 | 18 | go-version: ${{matrix.go}} |
21 | 19 | |
22 | 20 | - name: checkout |
23 | uses: actions/checkout@v2 | |
24 | ||
25 | - name: tools | |
26 | run: go get golang.org/x/lint/golint | |
21 | uses: actions/checkout@v3 | |
27 | 22 | |
28 | 23 | - name: test |
29 | 24 | run: make |
2 | 2 | Notable changes between releases. |
3 | 3 | |
4 | 4 | ## Latest |
5 | ||
6 | ## v1.4.1 | |
7 | ||
8 | * Update minimum Go version to v1.18 ([#76](https://github.com/dghubble/sling/pull/76)) | |
5 | 9 | |
6 | 10 | ## v1.4.0 |
7 | 11 |
0 | 0 | .PHONY: all |
1 | all: test vet lint fmt | |
1 | all: test vet fmt | |
2 | 2 | |
3 | 3 | .PHONY: test |
4 | 4 | test: |
8 | 8 | vet: |
9 | 9 | @go vet -all . |
10 | 10 | |
11 | .PHONY: lint | |
12 | lint: | |
13 | @golint -set_exit_status ./... | |
14 | ||
15 | 11 | .PHONY: fmt |
16 | 12 | fmt: |
17 | 13 | @test -z $$(go fmt ./...) |
0 | # 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) | |
0 | # Sling [![GoDoc](https://pkg.go.dev/badge/github.com/dghubble/sling.svg)](https://pkg.go.dev/github.com/dghubble/sling) [![Workflow](https://github.com/dghubble/sling/actions/workflows/test.yaml/badge.svg)](https://github.com/dghubble/sling/actions/workflows/test.yaml?query=branch%3Amain) [![Coverage](https://gocover.io/_badge/github.com/dghubble/sling)](https://gocover.io/github.com/dghubble/sling) [![Sponsors](https://img.shields.io/github/sponsors/dghubble?logo=github)](https://github.com/sponsors/dghubble) [![Twitter](https://img.shields.io/badge/twitter-follow-1da1f2?logo=twitter)](https://twitter.com/dghubble) | |
1 | 1 | |
2 | 2 | <img align="right" src="https://storage.googleapis.com/dghubble/small-gopher-with-sling.png"> |
3 | 3 |
4 | 4 | responses. Check the examples to learn how to compose a Sling into your API |
5 | 5 | client. |
6 | 6 | |
7 | Usage | |
7 | # Usage | |
8 | 8 | |
9 | 9 | Use a Sling to set path, method, header, query, or body properties and create an |
10 | 10 | http.Request. |
17 | 17 | req, err := sling.New().Get("https://example.com").QueryStruct(params).Request() |
18 | 18 | client.Do(req) |
19 | 19 | |
20 | Path | |
20 | # Path | |
21 | 21 | |
22 | 22 | Use Path to set or extend the URL for created Requests. Extension means the |
23 | 23 | path will be resolved relative to the existing URL. |
30 | 30 | |
31 | 31 | req, err := sling.New().Post("http://upload.com/gophers") |
32 | 32 | |
33 | Headers | |
33 | # Headers | |
34 | 34 | |
35 | 35 | Add or Set headers for requests created by a Sling. |
36 | 36 | |
37 | 37 | s := sling.New().Base(baseUrl).Set("User-Agent", "Gophergram API Client") |
38 | 38 | req, err := s.New().Get("gophergram/list").Request() |
39 | 39 | |
40 | QueryStruct | |
40 | # QueryStruct | |
41 | 41 | |
42 | 42 | Define url parameter structs (https://godoc.org/github.com/google/go-querystring/query). |
43 | 43 | Use QueryStruct to encode a struct as query parameters on requests. |
58 | 58 | params := &IssueParams{Sort: "updated", State: "open"} |
59 | 59 | req, err := githubBase.New().Get(path).QueryStruct(params).Request() |
60 | 60 | |
61 | Json Body | |
61 | # Json Body | |
62 | 62 | |
63 | 63 | Define JSON tagged structs (https://golang.org/pkg/encoding/json/). |
64 | 64 | Use BodyJSON to JSON encode a struct as the Body on requests. |
82 | 82 | |
83 | 83 | Requests will include an "application/json" Content-Type header. |
84 | 84 | |
85 | Form Body | |
85 | # Form Body | |
86 | 86 | |
87 | 87 | Define url tagged structs (https://godoc.org/github.com/google/go-querystring/query). |
88 | 88 | Use BodyForm to form url encode a struct as the Body on requests. |
99 | 99 | Requests will include an "application/x-www-form-urlencoded" Content-Type |
100 | 100 | header. |
101 | 101 | |
102 | Plain Body | |
102 | # Plain Body | |
103 | 103 | |
104 | 104 | Use Body to set a plain io.Reader on requests created by a Sling. |
105 | 105 | |
108 | 108 | |
109 | 109 | Set a content type header, if desired (e.g. Set("Content-Type", "text/plain")). |
110 | 110 | |
111 | Extend a Sling | |
111 | # Extend a Sling | |
112 | 112 | |
113 | 113 | Each Sling generates an http.Request (say with some path and query params) |
114 | 114 | each time Request() is called, based on its state. When creating |
136 | 136 | |
137 | 137 | Recap: If you wish to extend a Sling, create a new child copy with New(). |
138 | 138 | |
139 | Receive | |
139 | # Receive | |
140 | 140 | |
141 | 141 | Define a JSON struct to decode a type from 2XX success responses. Use |
142 | 142 | ReceiveSuccess(successV interface{}) to send a new Request and decode the |
0 | 0 | module github.com/dghubble/sling |
1 | 1 | |
2 | go 1.16 | |
2 | go 1.18 | |
3 | 3 | |
4 | 4 | require github.com/google/go-querystring v1.1.0 |
1 | 1 | github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= |
2 | 2 | github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= |
3 | 3 | github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= |
4 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= | |
5 | 4 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
54 | 54 | // New returns a copy of a Sling for creating a new Sling with properties |
55 | 55 | // from a parent Sling. For example, |
56 | 56 | // |
57 | // parentSling := sling.New().Client(client).Base("https://api.io/") | |
58 | // fooSling := parentSling.New().Get("foo/") | |
59 | // barSling := parentSling.New().Get("bar/") | |
57 | // parentSling := sling.New().Client(client).Base("https://api.io/") | |
58 | // fooSling := parentSling.New().Get("foo/") | |
59 | // barSling := parentSling.New().Get("bar/") | |
60 | 60 | // |
61 | 61 | // fooSling and barSling will both use the same client, but send requests to |
62 | 62 | // https://api.io/foo/ and https://api.io/bar/ respectively. |