Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 1.22 mux support #570

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
test:
strategy:
matrix:
go-version: [ 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x ]
go-version: [ 1.22.x ]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ node_modules/
dist/
generated/
.vendor/
vendor
*.swp
.vscode/launch.json
.vscode/settings.json
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/markbates/goth

go 1.18
go 1.22

require (
github.com/go-chi/chi/v5 v5.1.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk=
Expand Down
9 changes: 6 additions & 3 deletions gothic/gothic.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -262,7 +261,6 @@ func Logout(res http.ResponseWriter, req *http.Request) error {
var GetProviderName = getProviderName

func getProviderName(req *http.Request) (string, error) {

// try to get it from the url param "provider"
if p := req.URL.Query().Get("provider"); p != "" {
return p, nil
Expand All @@ -288,6 +286,11 @@ func getProviderName(req *http.Request) (string, error) {
return p, nil
}

// try to get it from the route param for go >= 1.22
if p := req.PathValue("provider"); p != "" {
return p, nil
}

// try to get it from the go-context's value of providerContextKey key
if p, ok := req.Context().Value(ProviderParamKey).(string); ok {
return p, nil
Expand Down Expand Up @@ -347,7 +350,7 @@ func getSessionValue(session *sessions.Session, key string) (string, error) {
if err != nil {
return "", err
}
s, err := ioutil.ReadAll(r)
s, err := io.ReadAll(r)
if err != nil {
return "", err
}
Expand Down
8 changes: 5 additions & 3 deletions gothic/gothic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"compress/gzip"
"fmt"
"html"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -98,8 +98,9 @@ func Test_GetAuthURL(t *testing.T) {
a := assert.New(t)

res := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/auth?provider=faux", nil)
req, err := http.NewRequest("GET", "/auth", nil)
a.NoError(err)
req.SetPathValue("provider", "faux")

u, err := GetAuthURL(res, req)
a.NoError(err)
Expand All @@ -118,6 +119,7 @@ func Test_GetAuthURL(t *testing.T) {
// auth URL has a different state from the previous one.
req2, err := http.NewRequest("GET", "/auth?provider=faux", nil)
a.NoError(err)
req2.SetPathValue("provider", "faux")
url2, err := GetAuthURL(httptest.NewRecorder(), req2)
a.NoError(err)
parsed2, err := url.Parse(url2)
Expand Down Expand Up @@ -283,7 +285,7 @@ func ungzipString(value string) string {
if err != nil {
return "err"
}
s, err := ioutil.ReadAll(r)
s, err := io.ReadAll(r)
if err != nil {
return "err"
}
Expand Down
3 changes: 1 addition & 2 deletions providers/amazon/amazon.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"

Expand Down Expand Up @@ -95,7 +94,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode)
}

bits, err := ioutil.ReadAll(response.Body)
bits, err := io.ReadAll(response.Body)
if err != nil {
return user, err
}
Expand Down
3 changes: 1 addition & 2 deletions providers/azureadv2/azureadv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"

"github.com/markbates/goth"
Expand Down Expand Up @@ -199,7 +198,7 @@ func userFromReader(r io.Reader, user *goth.User) error {
UserPrincipalName string `json:"userPrincipalName"` // The user's principal name.
}{}

userBytes, err := ioutil.ReadAll(r)
userBytes, err := io.ReadAll(r)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions providers/battlenet/battlenet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/markbates/goth"
Expand Down Expand Up @@ -103,7 +103,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode)
}

bits, err := ioutil.ReadAll(response.Body)
bits, err := io.ReadAll(response.Body)
if err != nil {
return user, err
}
Expand Down
4 changes: 2 additions & 2 deletions providers/bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/markbates/goth"
Expand Down Expand Up @@ -134,7 +134,7 @@ func (p *Provider) getUserInfo(user *goth.User, sess *Session) error {
return fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode)
}

bits, err := ioutil.ReadAll(response.Body)
bits, err := io.ReadAll(response.Body)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions providers/bitly/bitly.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"

"github.com/markbates/goth"
Expand Down Expand Up @@ -97,7 +96,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
}
defer resp.Body.Close()

buf, err := ioutil.ReadAll(resp.Body)
buf, err := io.ReadAll(resp.Body)
if err != nil {
return u, err
}
Expand Down
4 changes: 2 additions & 2 deletions providers/classlink/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/markbates/goth"
Expand Down Expand Up @@ -102,7 +102,7 @@ func (p Provider) FetchUser(session goth.Session) (goth.User, error) {

defer resp.Body.Close()

bytes, err := ioutil.ReadAll(resp.Body)
bytes, err := io.ReadAll(resp.Body)
if err != nil {
return user, err
}
Expand Down
3 changes: 1 addition & 2 deletions providers/cloudfoundry/cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"

Expand Down Expand Up @@ -104,7 +103,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, resp.StatusCode)
}

bits, err := ioutil.ReadAll(resp.Body)
bits, err := io.ReadAll(resp.Body)
if err != nil {
return user, err
}
Expand Down
3 changes: 1 addition & 2 deletions providers/cognito/cognito.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"

"github.com/markbates/goth"
Expand Down Expand Up @@ -128,7 +127,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode)
}

bits, err := ioutil.ReadAll(response.Body)
bits, err := io.ReadAll(response.Body)
if err != nil {
return user, err
}
Expand Down
3 changes: 1 addition & 2 deletions providers/dailymotion/dailymotion.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"

Expand Down Expand Up @@ -97,7 +96,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode)
}

bits, err := ioutil.ReadAll(response.Body)
bits, err := io.ReadAll(response.Body)
if err != nil {
return user, err
}
Expand Down
3 changes: 1 addition & 2 deletions providers/deezer/deezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -98,7 +97,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode)
}

bits, err := ioutil.ReadAll(response.Body)
bits, err := io.ReadAll(response.Body)
if err != nil {
return user, err
}
Expand Down
3 changes: 1 addition & 2 deletions providers/digitalocean/digitalocean.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"

"github.com/markbates/goth"
Expand Down Expand Up @@ -105,7 +104,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, resp.StatusCode)
}

bits, err := ioutil.ReadAll(resp.Body)
bits, err := io.ReadAll(resp.Body)
if err != nil {
return user, err
}
Expand Down
3 changes: 1 addition & 2 deletions providers/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"

"github.com/markbates/goth"
Expand Down Expand Up @@ -143,7 +142,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, resp.StatusCode)
}

bits, err := ioutil.ReadAll(resp.Body)
bits, err := io.ReadAll(resp.Body)
if err != nil {
return user, err
}
Expand Down
3 changes: 1 addition & 2 deletions providers/dropbox/dropbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"

Expand Down Expand Up @@ -105,7 +104,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, resp.StatusCode)
}

bits, err := ioutil.ReadAll(resp.Body)
bits, err := io.ReadAll(resp.Body)
if err != nil {
return user, err
}
Expand Down
4 changes: 2 additions & 2 deletions providers/eveonline/eveonline.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/markbates/goth"
Expand Down Expand Up @@ -102,7 +102,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode)
}

bits, err := ioutil.ReadAll(response.Body)
bits, err := io.ReadAll(response.Body)
if err != nil {
return user, err
}
Expand Down
3 changes: 1 addition & 2 deletions providers/facebook/facebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -127,7 +126,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode)
}

bits, err := ioutil.ReadAll(response.Body)
bits, err := io.ReadAll(response.Body)
if err != nil {
return user, err
}
Expand Down
3 changes: 1 addition & 2 deletions providers/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -115,7 +114,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, response.StatusCode)
}

bits, err := ioutil.ReadAll(response.Body)
bits, err := io.ReadAll(response.Body)
if err != nil {
return user, err
}
Expand Down
3 changes: 1 addition & 2 deletions providers/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -126,7 +125,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("GitHub API responded with a %d trying to fetch user information", response.StatusCode)
}

bits, err := ioutil.ReadAll(response.Body)
bits, err := io.ReadAll(response.Body)
if err != nil {
return user, err
}
Expand Down
Loading
Loading