Codebase list golang-github-dghubble-sling / fresh-releases/upstream
Import upstream version 1.4.1 Debian Janitor 1 year, 3 days ago
9 changed file(s) with 24 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
11 on:
22 push:
33 branches:
4 - master
4 - main
55 pull_request:
6 branches:
7 - master
86 jobs:
97 build:
108 name: go
1210 strategy:
1311 fail-fast: false
1412 matrix:
15 go: ['1.16', '1.17']
13 go: ['1.18', '1.19']
1614 steps:
1715 - name: setup
18 uses: actions/setup-go@v2
16 uses: actions/setup-go@v3
1917 with:
2018 go-version: ${{matrix.go}}
2119
2220 - 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
2722
2823 - name: test
2924 run: make
22 Notable changes between releases.
33
44 ## Latest
5
6 ## v1.4.1
7
8 * Update minimum Go version to v1.18 ([#76](https://github.com/dghubble/sling/pull/76))
59
610 ## v1.4.0
711
00 .PHONY: all
1 all: test vet lint fmt
1 all: test vet fmt
22
33 .PHONY: test
44 test:
88 vet:
99 @go vet -all .
1010
11 .PHONY: lint
12 lint:
13 @golint -set_exit_status ./...
14
1511 .PHONY: fmt
1612 fmt:
1713 @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)
11
22 <img align="right" src="https://storage.googleapis.com/dghubble/small-gopher-with-sling.png">
33
44 responses. Check the examples to learn how to compose a Sling into your API
55 client.
66
7 Usage
7 # Usage
88
99 Use a Sling to set path, method, header, query, or body properties and create an
1010 http.Request.
1717 req, err := sling.New().Get("https://example.com").QueryStruct(params).Request()
1818 client.Do(req)
1919
20 Path
20 # Path
2121
2222 Use Path to set or extend the URL for created Requests. Extension means the
2323 path will be resolved relative to the existing URL.
3030
3131 req, err := sling.New().Post("http://upload.com/gophers")
3232
33 Headers
33 # Headers
3434
3535 Add or Set headers for requests created by a Sling.
3636
3737 s := sling.New().Base(baseUrl).Set("User-Agent", "Gophergram API Client")
3838 req, err := s.New().Get("gophergram/list").Request()
3939
40 QueryStruct
40 # QueryStruct
4141
4242 Define url parameter structs (https://godoc.org/github.com/google/go-querystring/query).
4343 Use QueryStruct to encode a struct as query parameters on requests.
5858 params := &IssueParams{Sort: "updated", State: "open"}
5959 req, err := githubBase.New().Get(path).QueryStruct(params).Request()
6060
61 Json Body
61 # Json Body
6262
6363 Define JSON tagged structs (https://golang.org/pkg/encoding/json/).
6464 Use BodyJSON to JSON encode a struct as the Body on requests.
8282
8383 Requests will include an "application/json" Content-Type header.
8484
85 Form Body
85 # Form Body
8686
8787 Define url tagged structs (https://godoc.org/github.com/google/go-querystring/query).
8888 Use BodyForm to form url encode a struct as the Body on requests.
9999 Requests will include an "application/x-www-form-urlencoded" Content-Type
100100 header.
101101
102 Plain Body
102 # Plain Body
103103
104104 Use Body to set a plain io.Reader on requests created by a Sling.
105105
108108
109109 Set a content type header, if desired (e.g. Set("Content-Type", "text/plain")).
110110
111 Extend a Sling
111 # Extend a Sling
112112
113113 Each Sling generates an http.Request (say with some path and query params)
114114 each time Request() is called, based on its state. When creating
136136
137137 Recap: If you wish to extend a Sling, create a new child copy with New().
138138
139 Receive
139 # Receive
140140
141141 Define a JSON struct to decode a type from 2XX success responses. Use
142142 ReceiveSuccess(successV interface{}) to send a new Request and decode the
00 module github.com/dghubble/sling
11
2 go 1.16
2 go 1.18
33
44 require github.com/google/go-querystring v1.1.0
11 github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
22 github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
33 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=
54 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
5454 // New returns a copy of a Sling for creating a new Sling with properties
5555 // from a parent Sling. For example,
5656 //
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/")
6060 //
6161 // fooSling and barSling will both use the same client, but send requests to
6262 // https://api.io/foo/ and https://api.io/bar/ respectively.
768768 <temperature>10.5</temperature>
769769 </response>`
770770 fmt.Fprintf(w, xml.Header)
771 fmt.Fprintf(w, data)
771 fmt.Fprint(w, data)
772772 })
773773
774774 endpoint := New().Client(client).Base("http://example.com/").Path("foo/").Post("submit")