(experimental) upgraded to encoding/json/v2

This commit is contained in:
Gani Georgiev committed 2026-08-18 18:16:22 +03:00
1 parent 4d4275c9aa
commit 97dd775455
125 files changed
+433 -364

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"errors"
"fmt"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"errors"
"net/http"
+3 -3
View File
@@ -3,7 +3,7 @@ package auth
import (
"bytes"
"context"
"encoding/json"
"encoding/json/v2"
"testing"
"golang.org/x/oauth2"
@@ -215,12 +215,12 @@ func TestExtra(t *testing.T) {
after := b.Extra()
rawExtra, err := json.Marshal(extra)
rawExtra, err := json.Marshal(extra, json.Deterministic(true))
if err != nil {
t.Fatal(err)
}
rawAfter, err := json.Marshal(after)
rawAfter, err := json.Marshal(after, json.Deterministic(true))
if err != nil {
t.Fatal(err)
}
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"errors"
"io"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"fmt"
"github.com/pocketbase/pocketbase/tools/types"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"fmt"
"github.com/pocketbase/pocketbase/tools/types"
+8 -6
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"github.com/pocketbase/pocketbase/tools/types"
"golang.org/x/oauth2"
@@ -53,12 +53,14 @@ func (p *Facebook) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) {
}
extracted := struct {
Id string
Name string
Email string
Id string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Picture struct {
Data struct{ Url string }
}
Data struct {
Url string `json:"url"`
} `json:"data"`
} `json:"picture"`
}{}
if err := json.Unmarshal(data, &extracted); err != nil {
return nil, err
+4 -4
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"errors"
"fmt"
"io"
@@ -119,9 +119,9 @@ func (p *Gitea) fetchVerifiedPrimaryEmail(token *oauth2.Token) (string, error) {
}
emails := []struct {
Email string
Verified bool
Primary bool
Email string `json:"email"`
Verified bool `json:"verified"`
Primary bool `json:"primary"`
}{}
if err := json.Unmarshal(content, &emails); err != nil {
return "", err
+4 -4
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"io"
"strconv"
@@ -120,9 +120,9 @@ func (p *Gitee) fetchPrimaryEmail(token *oauth2.Token) (string, error) {
}
emails := []struct {
Email string
State string
Scope []string
Email string `json:"email"`
State string `json:"state"`
Scope []string `json:"scope"`
}{}
if err := json.Unmarshal(content, &emails); err != nil {
// ignore unmarshal error in case "Keep my email address private"
+4 -4
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"io"
"strconv"
@@ -116,9 +116,9 @@ func (p *Github) fetchVerifiedPrimaryEmail(token *oauth2.Token) (string, error)
}
emails := []struct {
Email string
Verified bool
Primary bool
Email string `json:"email"`
Verified bool `json:"verified"`
Primary bool `json:"primary"`
}{}
if err := json.Unmarshal(content, &emails); err != nil {
return "", err
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"strconv"
"time"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"github.com/pocketbase/pocketbase/tools/types"
"golang.org/x/oauth2"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"github.com/pocketbase/pocketbase/tools/types"
"golang.org/x/oauth2"
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"crypto/ed25519"
"crypto/rsa"
"encoding/base64"
"encoding/json"
"encoding/json/v2"
"errors"
"fmt"
"io"
@@ -105,7 +105,7 @@ func Fetch(ctx context.Context, jwksURL string, kid string) (*JWK, error) {
}
jwks := struct {
Keys []*JWK
Keys []*JWK `json:"keys"`
}{}
err = json.Unmarshal(rawBody, &jwks)
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"crypto/rand"
"crypto/rsa"
"encoding/base64"
"encoding/json"
"encoding/json/v2"
"fmt"
"math/big"
"net/http"
@@ -252,7 +252,7 @@ func TestValidateTokenSignature(t *testing.T) {
}
server := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
_ = json.NewEncoder(res).Encode(map[string]any{"keys": []*jwk.JWK{
_ = json.MarshalWrite(res, map[string]any{"keys": []*jwk.JWK{
{
Kid: "key1",
Kty: "OKP",
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"strconv"
"github.com/pocketbase/pocketbase/tools/types"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"github.com/pocketbase/pocketbase/tools/types"
"golang.org/x/oauth2"
+1 -2
View File
@@ -3,7 +3,7 @@ package auth
import (
"bytes"
"context"
"encoding/json"
"encoding/json/v2"
"errors"
"net/http"
@@ -68,7 +68,6 @@ func (p *Linear) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) {
} `json:"viewer"`
} `json:"data"`
}{}
if err := json.Unmarshal(data, &extracted); err != nil {
return nil, err
}
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"github.com/pocketbase/pocketbase/tools/types"
"golang.org/x/oauth2"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"errors"
"strings"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"errors"
"slices"
+1 -1
View File
@@ -3,7 +3,7 @@ package auth
import (
"bytes"
"context"
"encoding/json"
"encoding/json/v2"
"errors"
"net/http"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"net/http"
"github.com/pocketbase/pocketbase/tools/types"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"errors"
"fmt"
"os"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"github.com/pocketbase/pocketbase/tools/types"
"golang.org/x/oauth2"
+2 -2
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"errors"
"github.com/pocketbase/pocketbase/tools/types"
@@ -62,7 +62,7 @@ func (p *Planningcenter) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) {
// don't map the email because users can have multiple assigned
// and it's not clear if they are verified
}
}
} `json:"data"`
}{}
if err := json.Unmarshal(data, &extracted); err != nil {
return nil, err
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"github.com/pocketbase/pocketbase/tools/types"
"golang.org/x/oauth2"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"strconv"
"github.com/pocketbase/pocketbase/tools/types"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"net/http"
"github.com/pocketbase/pocketbase/tools/types"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"errors"
"net/http"
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"github.com/pocketbase/pocketbase/tools/types"
"golang.org/x/oauth2"
+1 -2
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"errors"
"fmt"
"strconv"
@@ -69,7 +69,6 @@ func (p *VK) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) {
AvatarURL string `json:"photo_max"`
} `json:"response"`
}{}
if err := json.Unmarshal(data, &extracted); err != nil {
return nil, err
}
+1 -2
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"github.com/pocketbase/pocketbase/tools/types"
"golang.org/x/oauth2"
@@ -62,7 +62,6 @@ func (p *Wakatime) FetchAuthUser(token *oauth2.Token) (*AuthUser, error) {
IsEmailConfirmed bool `json:"is_email_confirmed"`
} `json:"data"`
}{}
if err := json.Unmarshal(data, &extracted); err != nil {
return nil, err
}
+1 -1
View File
@@ -2,7 +2,7 @@ package auth
import (
"context"
"encoding/json"
"encoding/json/v2"
"github.com/pocketbase/pocketbase/tools/types"
"golang.org/x/oauth2"