Skip to content

Commit

Permalink
refactor(gen): use cmp and slices from stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Nov 4, 2024
1 parent d13fbbe commit f44ff70
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions internal/gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gen

import (
"bytes"
"cmp"
"encoding/json"
"fmt"
"net/http"
Expand Down Expand Up @@ -256,7 +257,7 @@ func (g *Generator) mkInput(rule HTTPRule, m *protogen.Method, op *ogen.Operatio
values := maps.Values(fields)
// Sort to make output stable.
slices.SortStableFunc(values, func(a, b *protogen.Field) int {
return strings.Compare(string(a.Desc.FullName()), string(b.Desc.FullName()))
return cmp.Compare(string(a.Desc.FullName()), string(b.Desc.FullName()))
})
if err := g.mkJSONFields(s, values); err != nil {
return "", errors.Wrap(err, "make requestBody schema")
Expand Down Expand Up @@ -296,9 +297,9 @@ func (g *Generator) mkInput(rule HTTPRule, m *protogen.Method, op *ogen.Operatio
// Sort to make output stable.
slices.SortStableFunc(op.Parameters, func(a, b *ogen.Parameter) int {
if a.In != b.In {
return strings.Compare(a.In, b.In)
return cmp.Compare(a.In, b.In)
}
return strings.Compare(a.Name, b.Name)
return cmp.Compare(a.Name, b.Name)
})

return tmpl.String(), nil
Expand Down
2 changes: 1 addition & 1 deletion internal/gen/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"fmt"
"os"
"path"
"slices"
"strings"
"sync"

"github.com/go-faster/errors"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
goimports "golang.org/x/tools/imports"
"google.golang.org/protobuf/compiler/protogen"

Expand Down

0 comments on commit f44ff70

Please sign in to comment.