Skip to content

Commit f44ff70

Browse files
committed
refactor(gen): use cmp and slices from stdlib
1 parent d13fbbe commit f44ff70

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

internal/gen/generator.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gen
22

33
import (
44
"bytes"
5+
"cmp"
56
"encoding/json"
67
"fmt"
78
"net/http"
@@ -256,7 +257,7 @@ func (g *Generator) mkInput(rule HTTPRule, m *protogen.Method, op *ogen.Operatio
256257
values := maps.Values(fields)
257258
// Sort to make output stable.
258259
slices.SortStableFunc(values, func(a, b *protogen.Field) int {
259-
return strings.Compare(string(a.Desc.FullName()), string(b.Desc.FullName()))
260+
return cmp.Compare(string(a.Desc.FullName()), string(b.Desc.FullName()))
260261
})
261262
if err := g.mkJSONFields(s, values); err != nil {
262263
return "", errors.Wrap(err, "make requestBody schema")
@@ -296,9 +297,9 @@ func (g *Generator) mkInput(rule HTTPRule, m *protogen.Method, op *ogen.Operatio
296297
// Sort to make output stable.
297298
slices.SortStableFunc(op.Parameters, func(a, b *ogen.Parameter) int {
298299
if a.In != b.In {
299-
return strings.Compare(a.In, b.In)
300+
return cmp.Compare(a.In, b.In)
300301
}
301-
return strings.Compare(a.Name, b.Name)
302+
return cmp.Compare(a.Name, b.Name)
302303
})
303304

304305
return tmpl.String(), nil

internal/gen/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"fmt"
77
"os"
88
"path"
9+
"slices"
910
"strings"
1011
"sync"
1112

1213
"github.com/go-faster/errors"
1314
"golang.org/x/exp/maps"
14-
"golang.org/x/exp/slices"
1515
goimports "golang.org/x/tools/imports"
1616
"google.golang.org/protobuf/compiler/protogen"
1717

0 commit comments

Comments
 (0)