refactor: use slices package for sort (#10132)

The sort package is still used in places that were not trivial to
change. Since Go 1.21 slices package can be uswed for sort. See
https://go.dev/doc/go1.21#slices

### Purpose

Make some progress with the migration to a more up-to-date syntax.
This commit is contained in:
Marcel Meyer
2025-05-26 13:37:26 +02:00
committed by GitHub
parent 58c85fc9db
commit 48b757cac1
29 changed files with 85 additions and 80 deletions
+4 -3
View File
@@ -8,6 +8,7 @@ package main
import ( import (
"bytes" "bytes"
"cmp"
"compress/gzip" "compress/gzip"
"context" "context"
"io" "io"
@@ -15,7 +16,7 @@ import (
"math" "math"
"os" "os"
"path/filepath" "path/filepath"
"sort" "slices"
"time" "time"
) )
@@ -177,8 +178,8 @@ func (d *diskStore) inventory() error {
}) })
return nil return nil
}) })
sort.Slice(d.currentFiles, func(i, j int) bool { slices.SortFunc(d.currentFiles, func(a, b currentFile) int {
return d.currentFiles[i].mtime < d.currentFiles[j].mtime return cmp.Compare(a.mtime, b.mtime)
}) })
var oldest time.Duration var oldest time.Duration
if len(d.currentFiles) > 0 { if len(d.currentFiles) > 0 {
+4 -3
View File
@@ -7,9 +7,10 @@
package cli package cli
import ( import (
"cmp"
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"sort" "slices"
"github.com/syncthing/syncthing/lib/db" "github.com/syncthing/syncthing/lib/db"
) )
@@ -77,8 +78,8 @@ func indexDumpSize() error {
elems = append(elems, ele) elems = append(elems, ele)
} }
sort.Slice(elems, func(i, j int) bool { slices.SortFunc(elems, func(a, b sizedElement) int {
return elems[i].size > elems[j].size return cmp.Compare(b.size, a.size)
}) })
for _, ele := range elems { for _, ele := range elems {
fmt.Println(ele.key, ele.size) fmt.Println(ele.key, ele.size)
+6 -5
View File
@@ -8,10 +8,11 @@ package cli
import ( import (
"bytes" "bytes"
"cmp"
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt" "fmt"
"sort" "slices"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@@ -207,11 +208,11 @@ func indexCheck() (err error) {
// Aggregate the ranges of missing sequence entries, print them // Aggregate the ranges of missing sequence entries, print them
sort.Slice(missingSeq, func(a, b int) bool { slices.SortFunc(missingSeq, func(a, b sequenceKey) int {
if missingSeq[a].folder != missingSeq[b].folder { if a.folder != b.folder {
return missingSeq[a].folder < missingSeq[b].folder return cmp.Compare(a.folder, b.folder)
} }
return missingSeq[a].sequence < missingSeq[b].sequence return cmp.Compare(a.sequence, b.sequence)
}) })
var folder uint32 var folder uint32
+2 -2
View File
@@ -23,7 +23,7 @@ import (
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime/pprof" "runtime/pprof"
"sort" "slices"
"strconv" "strconv"
"strings" "strings"
"syscall" "syscall"
@@ -443,7 +443,7 @@ func debugFacilities() string {
maxLen = len(name) maxLen = len(name)
} }
} }
sort.Strings(names) slices.Sort(names)
// Format the choices // Format the choices
b := new(bytes.Buffer) b := new(bytes.Buffer)
+8 -7
View File
@@ -8,6 +8,7 @@ package api
import ( import (
"bytes" "bytes"
"cmp"
"context" "context"
"crypto/tls" "crypto/tls"
"crypto/x509" "crypto/x509"
@@ -24,7 +25,7 @@ import (
"reflect" "reflect"
"runtime" "runtime"
"runtime/pprof" "runtime/pprof"
"sort" "slices"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@@ -750,7 +751,7 @@ func (*service) getSystemVersion(w http.ResponseWriter, _ *http.Request) {
func (*service) getSystemDebug(w http.ResponseWriter, _ *http.Request) { func (*service) getSystemDebug(w http.ResponseWriter, _ *http.Request) {
names := l.Facilities() names := l.Facilities()
enabled := l.FacilityDebugging() enabled := l.FacilityDebugging()
sort.Strings(enabled) slices.Sort(enabled)
sendJSON(w, map[string]interface{}{ sendJSON(w, map[string]interface{}{
"facilities": names, "facilities": names,
"enabled": enabled, "enabled": enabled,
@@ -1535,8 +1536,8 @@ func (*service) getLang(w http.ResponseWriter, r *http.Request) {
langs = append(langs, code) langs = append(langs, code)
} }
// Reorder by descending q value // Reorder by descending q value
sort.SliceStable(langs, func(i, j int) bool { slices.SortStableFunc(langs, func(i, j string) int {
return weights[langs[i]] > weights[langs[j]] return cmp.Compare(weights[j], weights[i])
}) })
sendJSON(w, langs) sendJSON(w, langs)
} }
@@ -1822,8 +1823,8 @@ func browseFiles(ffs fs.Filesystem, search string) []string {
} }
// sort to return matches in deterministic order (don't depend on file system order) // sort to return matches in deterministic order (don't depend on file system order)
sort.Strings(exactMatches) slices.Sort(exactMatches)
sort.Strings(caseInsMatches) slices.Sort(caseInsMatches)
return append(exactMatches, caseInsMatches...) return append(exactMatches, caseInsMatches...)
} }
@@ -1920,7 +1921,7 @@ func dirNames(dir string) []string {
} }
} }
sort.Strings(dirs) slices.Sort(dirs)
return dirs return dirs
} }
+2 -2
View File
@@ -12,7 +12,7 @@ import (
"os" "os"
"regexp" "regexp"
"runtime" "runtime"
"sort" "slices"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@@ -109,7 +109,7 @@ func TagsList() []string {
tags = append(tags, Extra) tags = append(tags, Extra)
} }
sort.Strings(tags) slices.Sort(tags)
return tags return tags
} }
+3 -2
View File
@@ -17,6 +17,7 @@ import (
"net/url" "net/url"
"os" "os"
"reflect" "reflect"
"slices"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@@ -380,8 +381,8 @@ func (cfg *Configuration) prepareFolders(myID protocol.DeviceID, existingDevices
} }
} }
// Ensure that the folder list is sorted by ID // Ensure that the folder list is sorted by ID
sort.Slice(cfg.Folders, func(a, b int) bool { slices.SortFunc(cfg.Folders, func(a, b FolderConfiguration) int {
return cfg.Folders[a].ID < cfg.Folders[b].ID return strings.Compare(a.ID, b.ID)
}) })
return sharedFolders, nil return sharedFolders, nil
} }
+2 -2
View File
@@ -17,7 +17,7 @@ import (
"path/filepath" "path/filepath"
"reflect" "reflect"
"runtime" "runtime"
"sort" "slices"
"strings" "strings"
"testing" "testing"
@@ -911,7 +911,7 @@ func TestV14ListenAddressesMigration(t *testing.T) {
t.Error("Configuration was not converted") t.Error("Configuration was not converted")
} }
sort.Strings(tc[2]) slices.Sort(tc[2])
if !reflect.DeepEqual(cfg.Options.RawListenAddresses, tc[2]) { if !reflect.DeepEqual(cfg.Options.RawListenAddresses, tc[2]) {
t.Errorf("Migration error; actual %#v != expected %#v", cfg.Options.RawListenAddresses, tc[2]) t.Errorf("Migration error; actual %#v != expected %#v", cfg.Options.RawListenAddresses, tc[2])
} }
+5 -4
View File
@@ -7,11 +7,12 @@
package config package config
import ( import (
"cmp"
"net/url" "net/url"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"sort" "slices"
"strings" "strings"
"sync" "sync"
@@ -65,8 +66,8 @@ type migrationSet []migration
func (ms migrationSet) apply(cfg *Configuration) { func (ms migrationSet) apply(cfg *Configuration) {
// Make sure we apply the migrations in target version order regardless // Make sure we apply the migrations in target version order regardless
// of how it was defined. // of how it was defined.
sort.Slice(ms, func(a, b int) bool { slices.SortFunc(ms, func(a, b migration) int {
return ms[a].targetVersion < ms[b].targetVersion return cmp.Compare(a.targetVersion, b.targetVersion)
}) })
// Apply all migrations. // Apply all migrations.
@@ -349,7 +350,7 @@ func migrateToConfigV14(cfg *Configuration) {
cfg.Options.DeprecatedRelayServers = nil cfg.Options.DeprecatedRelayServers = nil
// For consistency // For consistency
sort.Strings(cfg.Options.RawListenAddresses) slices.Sort(cfg.Options.RawListenAddresses)
var newAddrs []string var newAddrs []string
for _, addr := range cfg.Options.RawGlobalAnnServers { for _, addr := range cfg.Options.RawGlobalAnnServers {
+4 -3
View File
@@ -9,7 +9,8 @@ package config
import ( import (
"encoding/json" "encoding/json"
"encoding/xml" "encoding/xml"
"sort" "slices"
"strings"
"github.com/syncthing/syncthing/lib/structutil" "github.com/syncthing/syncthing/lib/structutil"
) )
@@ -84,8 +85,8 @@ func (c *VersioningConfiguration) toInternal() internalVersioningConfiguration {
for k, v := range c.Params { for k, v := range c.Params {
tmp.Params = append(tmp.Params, internalParam{k, v}) tmp.Params = append(tmp.Params, internalParam{k, v})
} }
sort.Slice(tmp.Params, func(a, b int) bool { slices.SortFunc(tmp.Params, func(a, b internalParam) int {
return tmp.Params[a].Key < tmp.Params[b].Key return strings.Compare(a.Key, b.Key)
}) })
return tmp return tmp
} }
+1 -2
View File
@@ -23,7 +23,6 @@ import (
"net" "net"
"net/url" "net/url"
"slices" "slices"
"sort"
"strings" "strings"
stdsync "sync" stdsync "sync"
"time" "time"
@@ -1151,7 +1150,7 @@ func (s *service) dialParallel(ctx context.Context, deviceID protocol.DeviceID,
} }
// Sort the priorities so that we dial lowest first (which means highest...) // Sort the priorities so that we dial lowest first (which means highest...)
sort.Ints(priorities) slices.Sort(priorities)
sema := semaphore.MultiSemaphore{semaphore.New(dialMaxParallelPerDevice), parentSema} sema := semaphore.MultiSemaphore{semaphore.New(dialMaxParallelPerDevice), parentSema}
for _, prio := range priorities { for _, prio := range priorities {
+2 -2
View File
@@ -8,7 +8,7 @@ package db
import ( import (
"encoding/binary" "encoding/binary"
"sort" "slices"
"github.com/syncthing/syncthing/lib/db/backend" "github.com/syncthing/syncthing/lib/db/backend"
"github.com/syncthing/syncthing/lib/sync" "github.com/syncthing/syncthing/lib/sync"
@@ -147,6 +147,6 @@ func (i *smallIndex) Values() []string {
} }
i.mut.Unlock() i.mut.Unlock()
sort.Strings(vals) slices.Sort(vals)
return vals return vals
} }
+2 -2
View File
@@ -13,7 +13,7 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"sort" "slices"
"time" "time"
"github.com/thejerf/suture/v4" "github.com/thejerf/suture/v4"
@@ -159,7 +159,7 @@ func (m *manager) Lookup(ctx context.Context, deviceID protocol.DeviceID) (addre
m.mut.RUnlock() m.mut.RUnlock()
addresses = stringutil.UniqueTrimmedStrings(addresses) addresses = stringutil.UniqueTrimmedStrings(addresses)
sort.Strings(addresses) slices.Sort(addresses)
l.Debugln("lookup results for", deviceID) l.Debugln("lookup results for", deviceID)
l.Debugln(" addresses: ", addresses) l.Debugln(" addresses: ", addresses)
+6 -7
View File
@@ -12,7 +12,7 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"sort" "slices"
"strconv" "strconv"
"strings" "strings"
"syscall" "syscall"
@@ -218,7 +218,7 @@ func TestDirNames(t *testing.T) {
"a", "a",
"bC", "bC",
} }
sort.Strings(testCases) slices.Sort(testCases)
for _, sub := range testCases { for _, sub := range testCases {
if err := os.Mkdir(filepath.Join(dir, sub), 0o777); err != nil { if err := os.Mkdir(filepath.Join(dir, sub), 0o777); err != nil {
@@ -229,7 +229,7 @@ func TestDirNames(t *testing.T) {
if dirs, err := fs.DirNames("."); err != nil || len(dirs) != len(testCases) { if dirs, err := fs.DirNames("."); err != nil || len(dirs) != len(testCases) {
t.Errorf("%s %s %s", err, dirs, testCases) t.Errorf("%s %s %s", err, dirs, testCases)
} else { } else {
sort.Strings(dirs) slices.Sort(dirs)
for i := range dirs { for i := range dirs {
if dirs[i] != testCases[i] { if dirs[i] != testCases[i] {
t.Errorf("%s != %s", dirs[i], testCases[i]) t.Errorf("%s != %s", dirs[i], testCases[i])
@@ -321,8 +321,8 @@ func TestGlob(t *testing.T) {
for _, testCase := range testCases { for _, testCase := range testCases {
results, err := fs.Glob(testCase.pattern) results, err := fs.Glob(testCase.pattern)
sort.Strings(results) slices.Sort(results)
sort.Strings(testCase.matches) slices.Sort(testCase.matches)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
@@ -628,8 +628,7 @@ func TestXattr(t *testing.T) {
Value: value, Value: value,
}) })
} }
sort.Slice(attrs, func(i, j int) bool { return attrs[i].Name < attrs[j].Name }) slices.SortFunc(attrs, func(a, b protocol.Xattr) int { return strings.Compare(a.Name, b.Name) })
// Set the xattrs, read them back and compare // Set the xattrs, read them back and compare
if err := tfs.SetXattr("/test", attrs, testXattrFilter{}); err != nil { if err := tfs.SetXattr("/test", attrs, testXattrFilter{}); err != nil {
t.Fatal(err) t.Fatal(err)
+2 -2
View File
@@ -12,7 +12,7 @@ package fs
import ( import (
"errors" "errors"
"fmt" "fmt"
"sort" "slices"
"unsafe" "unsafe"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@@ -69,7 +69,7 @@ func listXattr(path string) ([]string, error) {
} }
} }
sort.Strings(attrs) slices.Sort(attrs)
return attrs, nil return attrs, nil
} }
+2 -2
View File
@@ -12,7 +12,7 @@ package fs
import ( import (
"errors" "errors"
"fmt" "fmt"
"sort" "slices"
"strings" "strings"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@@ -38,6 +38,6 @@ func listXattr(path string) ([]string, error) {
buf = buf[:size] buf = buf[:size]
attrs := compact(strings.Split(string(buf), "\x00")) attrs := compact(strings.Split(string(buf), "\x00"))
sort.Strings(attrs) slices.Sort(attrs)
return attrs, nil return attrs, nil
} }
+2 -2
View File
@@ -11,7 +11,7 @@ import (
"fmt" "fmt"
"path/filepath" "path/filepath"
"runtime" "runtime"
"sort" "slices"
"strings" "strings"
"testing" "testing"
"time" "time"
@@ -344,7 +344,7 @@ func fakefsForBenchmark(nfiles int, latency time.Duration) (Filesystem, []string
return nil, nil, errors.New("didn't find enough stuff") return nil, nil, errors.New("didn't find enough stuff")
} }
sort.Strings(paths) slices.Sort(paths)
return fsys, paths, nil return fsys, paths, nil
} }
+3 -3
View File
@@ -14,7 +14,7 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"sort" "slices"
"testing" "testing"
"time" "time"
@@ -369,8 +369,8 @@ func assertDir(t *testing.T, fs Filesystem, directory string, filenames []string
if path.Clean(directory) == "/" { if path.Clean(directory) == "/" {
filenames = append(filenames, ".stfolder") filenames = append(filenames, ".stfolder")
} }
sort.Strings(filenames) slices.Sort(filenames)
sort.Strings(got) slices.Sort(got)
if len(filenames) != len(got) { if len(filenames) != len(got) {
t.Errorf("want %s, got %s", filenames, got) t.Errorf("want %s, got %s", filenames, got)
+2 -1
View File
@@ -12,6 +12,7 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"path/filepath" "path/filepath"
"slices"
"sort" "sort"
"time" "time"
@@ -1341,7 +1342,7 @@ func unifySubs(dirs []string, exists func(dir string) bool) []string {
if len(dirs) == 0 { if len(dirs) == 0 {
return nil return nil
} }
sort.Strings(dirs) slices.Sort(dirs)
if dirs[0] == "" || dirs[0] == "." || dirs[0] == string(fs.PathSeparator) { if dirs[0] == "" || dirs[0] == "." || dirs[0] == string(fs.PathSeparator) {
return nil return nil
} }
+2 -3
View File
@@ -18,7 +18,6 @@ import (
"path/filepath" "path/filepath"
"runtime/pprof" "runtime/pprof"
"slices" "slices"
"sort"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@@ -4092,8 +4091,8 @@ func equalStringsInAnyOrder(a, b []string) bool {
if len(a) != len(b) { if len(a) != len(b) {
return false return false
} }
sort.Strings(a) slices.Sort(a)
sort.Strings(b) slices.Sort(b)
for i := range a { for i := range a {
if a[i] != b[i] { if a[i] != b[i] {
return false return false
+2 -2
View File
@@ -10,7 +10,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"sort" "slices"
"sync" "sync"
"time" "time"
@@ -166,7 +166,7 @@ func relayAddressesOrder(ctx context.Context, input []string) []string {
ids = append(ids, id) ids = append(ids, id)
} }
sort.Ints(ids) slices.Sort(ids)
addresses := make([]string, 0, len(input)) addresses := make([]string, 0, len(input))
for _, id := range ids { for _, id := range ids {
+3 -3
View File
@@ -15,7 +15,7 @@ import (
"net/http" "net/http"
"os" "os"
"runtime" "runtime"
"sort" "slices"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -437,8 +437,8 @@ func printServiceTree(w io.Writer, sup supervisor, level int) {
printService(w, sup, level) printService(w, sup, level)
svcs := sup.Services() svcs := sup.Services()
sort.Slice(svcs, func(a, b int) bool { slices.SortFunc(svcs, func(a, b suture.Service) int {
return fmt.Sprint(svcs[a]) < fmt.Sprint(svcs[b]) return strings.Compare(fmt.Sprint(a), fmt.Sprint(b))
}) })
for _, svc := range svcs { for _, svc := range svcs {
+3 -3
View File
@@ -16,7 +16,7 @@ import (
"net/http" "net/http"
"os" "os"
"runtime" "runtime"
"sort" "slices"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -162,7 +162,7 @@ func (s *Service) reportData(ctx context.Context, urVersion int, preview bool) (
l.Warnf("Unhandled versioning type for usage reports: %s", cfg.Versioning.Type) l.Warnf("Unhandled versioning type for usage reports: %s", cfg.Versioning.Type)
} }
} }
sort.Ints(report.RescanIntvs) slices.Sort(report.RescanIntvs)
for _, cfg := range s.cfg.Devices() { for _, cfg := range s.cfg.Devices() {
if cfg.Introducer { if cfg.Introducer {
@@ -295,7 +295,7 @@ func (s *Service) reportData(ctx context.Context, urVersion int, preview bool) (
report.FolderUsesV3.SyncOwnership++ report.FolderUsesV3.SyncOwnership++
} }
} }
sort.Ints(report.FolderUsesV3.FsWatcherDelays) slices.Sort(report.FolderUsesV3.FsWatcherDelays)
for _, cfg := range s.cfg.Devices() { for _, cfg := range s.cfg.Devices() {
if cfg.Untrusted { if cfg.Untrusted {
+2 -2
View File
@@ -8,7 +8,7 @@ package versioner
import ( import (
"context" "context"
"sort" "slices"
"strconv" "strconv"
"time" "time"
@@ -79,7 +79,7 @@ func (v simple) toRemove(versions []string, now time.Time) []string {
var remove []string var remove []string
// The list of versions may or may not be properly sorted. // The list of versions may or may not be properly sorted.
sort.Strings(versions) slices.Sort(versions)
// If the amount of elements exceeds the limit: the oldest elements are to be removed. // If the amount of elements exceeds the limit: the oldest elements are to be removed.
if len(versions) > v.keep { if len(versions) > v.keep {
+2 -2
View File
@@ -9,7 +9,7 @@ package versioner
import ( import (
"context" "context"
"fmt" "fmt"
"sort" "slices"
"strconv" "strconv"
"time" "time"
@@ -69,7 +69,7 @@ func (v *staggered) toRemove(versions []string, now time.Time) []string {
var remove []string var remove []string
// The list of versions may or may not be properly sorted. // The list of versions may or may not be properly sorted.
sort.Strings(versions) slices.Sort(versions)
for _, version := range versions { for _, version := range versions {
versionTime, err := time.ParseInLocation(TimeFormat, extractTag(version), time.Local) versionTime, err := time.ParseInLocation(TimeFormat, extractTag(version), time.Local)
+3 -3
View File
@@ -9,7 +9,7 @@ package versioner
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"sort" "slices"
"strconv" "strconv"
"testing" "testing"
"time" "time"
@@ -97,7 +97,7 @@ func TestStaggeredVersioningVersionCount(t *testing.T) {
"test~20150416-135958", // 365 days 2 seconds ago "test~20150416-135958", // 365 days 2 seconds ago
"test~20150414-140000", // 367 days ago "test~20150414-140000", // 367 days ago
} }
sort.Strings(delete) slices.Sort(delete)
cfg := config.FolderConfiguration{ cfg := config.FolderConfiguration{
FilesystemType: config.FilesystemTypeBasic, FilesystemType: config.FilesystemTypeBasic,
@@ -111,7 +111,7 @@ func TestStaggeredVersioningVersionCount(t *testing.T) {
v := newStaggered(cfg).(*staggered) v := newStaggered(cfg).(*staggered)
rem := v.toRemove(versionsWithMtime, now) rem := v.toRemove(versionsWithMtime, now)
sort.Strings(rem) slices.Sort(rem)
if diff, equal := messagediff.PrettyDiff(delete, rem); !equal { if diff, equal := messagediff.PrettyDiff(delete, rem); !equal {
t.Errorf("Incorrect deleted files; got %v, expected %v\n%v", rem, delete, diff) t.Errorf("Incorrect deleted files; got %v, expected %v\n%v", rem, delete, diff)
+2 -2
View File
@@ -13,7 +13,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"sort" "slices"
"strings" "strings"
"time" "time"
@@ -339,7 +339,7 @@ func findAllVersions(fs fs.Filesystem, filePath string) []string {
return nil return nil
} }
versions = stringutil.UniqueTrimmedStrings(versions) versions = stringutil.UniqueTrimmedStrings(versions)
sort.Strings(versions) slices.Sort(versions)
return versions return versions
} }
+2 -2
View File
@@ -17,7 +17,7 @@ import (
"net/http" "net/http"
"os" "os"
"regexp" "regexp"
"sort" "slices"
"strings" "strings"
) )
@@ -93,7 +93,7 @@ func main() {
} }
func saveValidLangs(langs []string) { func saveValidLangs(langs []string) {
sort.Strings(langs) slices.Sort(langs)
fd, err := os.Create("valid-langs.js") fd, err := os.Create("valid-langs.js")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
+2 -2
View File
@@ -17,7 +17,7 @@ import (
"net/http" "net/http"
"os" "os"
"regexp" "regexp"
"sort" "slices"
"strings" "strings"
) )
@@ -116,7 +116,7 @@ func reformatLanguageCode(origCode string) string {
} }
func saveValidLangs(langs []string) { func saveValidLangs(langs []string) {
sort.Strings(langs) slices.Sort(langs)
fd, err := os.Create("valid-langs.js") fd, err := os.Create("valid-langs.js")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)