Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
10 changes: 6 additions & 4 deletions cmd/acceptguard/report.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package main

import (
"encoding/json"
"encoding/json/jsontext"
"encoding/json/v2"
"fmt"
"os"

"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
)

func writeJSON(path string, findings []finding) error {
Expand All @@ -13,10 +16,9 @@ func writeJSON(path string, findings []finding) error {
}
defer f.Close()

enc := json.NewEncoder(f)
enc.SetIndent("", " ")
enc := jsontext.NewEncoder(f, jsonx.V1(), jsontext.Multiline(true), jsontext.WithIndent(" "))

return enc.Encode(findings)
return json.MarshalEncode(enc, findings)
}

func printReport(findings []finding) {
Expand Down
6 changes: 4 additions & 2 deletions cmd/bdaudit/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package main

import (
"bufio"
"encoding/json"
"encoding/json/v2"
"fmt"
"os"
"strings"

"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
)

const statusClosed = "closed"
Expand Down Expand Up @@ -61,7 +63,7 @@ func loadIssues(path string) (map[string]issue, error) {
}

var iss issue
if unmarshalErr := json.Unmarshal([]byte(text), &iss); unmarshalErr != nil {
if unmarshalErr := json.Unmarshal([]byte(text), &iss, jsonx.V1()); unmarshalErr != nil {
return nil, fmt.Errorf("%s:%d: %w", path, line, unmarshalErr)
}
if iss.ID == "" {
Expand Down
10 changes: 6 additions & 4 deletions cmd/bdaudit/report.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package main

import (
"encoding/json"
"encoding/json/jsontext"
"encoding/json/v2"
"fmt"
"io"
"os"
"strings"

"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
)

type report struct {
Expand All @@ -23,10 +26,9 @@ func writeJSONReport(path string, rep report) error {
}
defer f.Close()

enc := json.NewEncoder(f)
enc.SetIndent("", " ")
enc := jsontext.NewEncoder(f, jsonx.V1(), jsontext.Multiline(true), jsontext.WithIndent(" "))

if encErr := enc.Encode(rep); encErr != nil {
if encErr := json.MarshalEncode(enc, rep); encErr != nil {
return fmt.Errorf("encode json: %w", encErr)
}

Expand Down
10 changes: 6 additions & 4 deletions cmd/bodyclass/report.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package main

import (
"encoding/json"
"encoding/json/jsontext"
"encoding/json/v2"
"fmt"
"os"
"sort"

"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
)

type serviceReport struct {
Expand Down Expand Up @@ -68,10 +71,9 @@ func writeJSON(path string, results []serviceReport) {
}
defer f.Close()

enc := json.NewEncoder(f)
enc.SetIndent("", " ")
enc := jsontext.NewEncoder(f, jsonx.V1(), jsontext.Multiline(true), jsontext.WithIndent(" "))

if encErr := enc.Encode(results); encErr != nil {
if encErr := json.MarshalEncode(enc, results); encErr != nil {
fatal(encErr)
}

Expand Down
19 changes: 11 additions & 8 deletions cmd/cfnattrgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
package main

import (
"encoding/json"
"encoding/json/jsontext"
"encoding/json/v2"
"flag"
"fmt"
"go/ast"
Expand All @@ -37,10 +38,12 @@ import (
"sort"
"strconv"
"strings"

"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
)

type resourceTypeSpec struct {
Attributes map[string]json.RawMessage `json:"Attributes"`
Attributes map[string]jsontext.Value `json:"Attributes"`
}

type resourceSpec struct {
Expand Down Expand Up @@ -158,15 +161,15 @@ func runTrimSpec(specPath, outPath string) error {
continue
}

attrs := make(map[string]json.RawMessage, len(rt.Attributes))
attrs := make(map[string]jsontext.Value, len(rt.Attributes))
for attr := range rt.Attributes {
attrs[attr] = json.RawMessage("{}")
attrs[attr] = jsontext.Value("{}")
}

trimmed.ResourceTypes[name] = resourceTypeSpec{Attributes: attrs}
}

out, err := json.MarshalIndent(trimmed, "", " ")
out, err := json.Marshal(trimmed, jsonx.V1(), jsontext.Multiline(true), jsontext.WithIndent(" "))
if err != nil {
return fmt.Errorf("marshal trimmed spec: %w", err)
}
Expand All @@ -187,7 +190,7 @@ func loadSpec(path string) (*resourceSpec, error) {
}

var spec resourceSpec
if unmarshalErr := json.Unmarshal(data, &spec); unmarshalErr != nil {
if unmarshalErr := json.Unmarshal(data, &spec, jsonx.V1()); unmarshalErr != nil {
return nil, unmarshalErr
}

Expand Down Expand Up @@ -295,7 +298,7 @@ func buildTable(spec *resourceSpec, supportedTypes map[string]struct{}) map[stri
}

func renderJSON(table map[string][]string) ([]byte, error) {
out, err := json.MarshalIndent(table, "", " ")
out, err := json.Marshal(table, jsonx.V1(), jsontext.Multiline(true), jsontext.WithIndent(" "))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -359,7 +362,7 @@ func buildServices(spec *resourceSpec, literals map[string]struct{}) []string {
const minTypeNameParts = 3

func renderServices(services []string) ([]byte, error) {
out, err := json.MarshalIndent(services, "", " ")
out, err := json.Marshal(services, jsonx.V1(), jsontext.Multiline(true), jsontext.WithIndent(" "))
if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/cfnattrgen/regen_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package main

import (
"encoding/json"
"encoding/json/v2"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
)

const (
Expand Down Expand Up @@ -90,7 +92,7 @@ func TestRenderJSON_Deterministic(t *testing.T) {
assert.Equal(t, first, second)

var roundTrip map[string][]string
require.NoError(t, json.Unmarshal(first, &roundTrip))
require.NoError(t, json.Unmarshal(first, &roundTrip, jsonx.V1()))
assert.Equal(t, table, roundTrip)
}

Expand Down
21 changes: 17 additions & 4 deletions cmd/cfnpropgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
package main

import (
"encoding/json"
"encoding/json/jsontext"
"encoding/json/v2"
"flag"
"fmt"
"os"
"slices"

"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
)

type propertySpec struct {
Expand Down Expand Up @@ -53,7 +56,7 @@ func readJSON(path string, v any) error {
return err
}

return json.Unmarshal(data, v)
return json.Unmarshal(data, v, jsonx.V1())
}

func run(specPath, typesPath, outPath, reqPath string) error {
Expand All @@ -67,7 +70,12 @@ func run(specPath, typesPath, outPath, reqPath string) error {
return fmt.Errorf("load types: %w", err)
}

out, err := json.MarshalIndent(buildSchemas(&spec, types), "", " ")
out, err := json.Marshal(
buildSchemas(&spec, types),
jsonx.V1(),
jsontext.Multiline(true),
jsontext.WithIndent(" "),
)
if err != nil {
return fmt.Errorf("render: %w", err)
}
Expand All @@ -80,7 +88,12 @@ func run(specPath, typesPath, outPath, reqPath string) error {
return nil
}

req, err := json.MarshalIndent(buildRequired(&spec, types), "", " ")
req, err := json.Marshal(
buildRequired(&spec, types),
jsonx.V1(),
jsontext.Multiline(true),
jsontext.WithIndent(" "),
)
if err != nil {
return fmt.Errorf("render required: %w", err)
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/clientcoverage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
package main

import (
"encoding/json"
"encoding/json/jsontext"
"encoding/json/v2"
"flag"
"fmt"
"go/ast"
Expand All @@ -49,6 +50,8 @@ import (
"regexp"
"sort"
"strings"

"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
)

var (
Expand Down Expand Up @@ -650,7 +653,7 @@ func loadOpcensus(path string) ([]opService, error) {
}

var services []opService
if unmarshalErr := json.Unmarshal(data, &services); unmarshalErr != nil {
if unmarshalErr := json.Unmarshal(data, &services, jsonx.V1()); unmarshalErr != nil {
return nil, fmt.Errorf("parse %s: %w", path, unmarshalErr)
}

Expand Down Expand Up @@ -692,7 +695,7 @@ func main() {
rpt := buildReport(services, result)

if *jsonPath != "" {
data, marshalErr := json.MarshalIndent(rpt, "", " ")
data, marshalErr := json.Marshal(rpt, jsonx.V1(), jsontext.Multiline(true), jsontext.WithIndent(" "))
if marshalErr != nil {
fmt.Fprintln(os.Stderr, "marshal report:", marshalErr)
os.Exit(1)
Expand Down
10 changes: 6 additions & 4 deletions cmd/enumcheck/report.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package main

import (
"encoding/json"
"encoding/json/jsontext"
"encoding/json/v2"
"fmt"
"os"

"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
)

func writeJSON(path string, findings []finding) error {
Expand All @@ -12,10 +15,9 @@ func writeJSON(path string, findings []finding) error {
return err
}

enc := json.NewEncoder(f)
enc.SetIndent("", " ")
enc := jsontext.NewEncoder(f, jsonx.V1(), jsontext.Multiline(true), jsontext.WithIndent(" "))

if encErr := enc.Encode(findings); encErr != nil {
if encErr := json.MarshalEncode(enc, findings); encErr != nil {
_ = f.Close()

return encErr
Expand Down
10 changes: 6 additions & 4 deletions cmd/errcodeaudit/report.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package main

import (
"encoding/json"
"encoding/json/jsontext"
"encoding/json/v2"
"fmt"
"os"

"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
)

func writeJSON(path string, findings []finding) error {
Expand All @@ -13,10 +16,9 @@ func writeJSON(path string, findings []finding) error {
}
defer f.Close()

enc := json.NewEncoder(f)
enc.SetIndent("", " ")
enc := jsontext.NewEncoder(f, jsonx.V1(), jsontext.Multiline(true), jsontext.WithIndent(" "))

return enc.Encode(findings)
return json.MarshalEncode(enc, findings)
}

func printReport(findings []finding) {
Expand Down
10 changes: 6 additions & 4 deletions cmd/errtargetaudit/report.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package main

import (
"encoding/json"
"encoding/json/jsontext"
"encoding/json/v2"
"fmt"
"os"
"sort"
"strings"

"github.com/blackbirdworks/gopherstack/pkgs/jsonx"
)

// lowResolutionThreshold gates the implausible-resolution guard --
Expand Down Expand Up @@ -211,10 +214,9 @@ func writeJSON(path string, scans []serviceScan) error {
}
defer f.Close()

enc := json.NewEncoder(f)
enc.SetIndent("", " ")
enc := jsontext.NewEncoder(f, jsonx.V1(), jsontext.Multiline(true), jsontext.WithIndent(" "))

return enc.Encode(scans)
return json.MarshalEncode(enc, scans)
}

func printServiceScan(sr serviceScan) {
Expand Down
Loading
Loading