Skip to content

Commit 3bc2d7b

Browse files
committed
chore: use more standard library functions
1 parent 7ca3ef1 commit 3bc2d7b

4 files changed

Lines changed: 8 additions & 25 deletions

File tree

generator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"maps"
1111
"os"
12+
"slices"
1213
"strings"
1314

1415
"github.com/goccy/go-yaml"
@@ -264,9 +265,8 @@ func (g *Generator) Generate() ([]byte, error) {
264265
useJSONNumber: g.useJSONNumber,
265266
})
266267
if len(imports) > 0 {
267-
importsSlice := sortedKeys(imports)
268268
fmt.Fprintf(buffer, "import (\n")
269-
for _, _import := range importsSlice {
269+
for _, _import := range slices.Sorted(maps.Keys(imports)) {
270270
fmt.Fprintf(buffer, "\"%s\"\n", _import)
271271
}
272272
fmt.Fprintf(buffer, ")\n")

jsonstruct_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package jsonstruct
22

33
import (
4+
"maps"
5+
"slices"
46
"testing"
57

68
"github.com/alecthomas/assert/v2"
@@ -22,7 +24,7 @@ func TestDefaultExportNameFunc(t *testing.T) {
2224
"123": "_123",
2325
"A|B": "A_B",
2426
}
25-
for _, name := range sortedKeys(expected) {
27+
for _, name := range slices.Sorted(maps.Keys(expected)) {
2628
t.Run(name, func(t *testing.T) {
2729
assert.Equal(t, expected[name], DefaultExportNameFunc(name, defaultAbbreviations))
2830
})

maps.go

Lines changed: 0 additions & 20 deletions
This file was deleted.

value.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7+
"maps"
8+
"slices"
79
"strings"
810
"time"
911

@@ -273,10 +275,9 @@ func (v *value) goType(observations int, options *generateOptions) goType {
273275
}
274276
}
275277
b := &bytes.Buffer{}
276-
properties := sortedKeys(v.objectProperties)
277278
fmt.Fprintf(b, "struct {\n")
278279
var unparsableProperties []string
279-
for _, property := range properties {
280+
for _, property := range slices.Sorted(maps.Keys(v.objectProperties)) {
280281
if isUnparsableProperty(property) {
281282
unparsableProperties = append(unparsableProperties, property)
282283
continue

0 commit comments

Comments
 (0)