Skip to content
This repository was archived by the owner on Jun 6, 2019. It is now read-only.

Commit 1f3006c

Browse files
committed
sort map keys
1 parent a40e35f commit 1f3006c

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

xorm/go.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"go/format"
1111
"reflect"
12+
"sort"
1213
"strings"
1314
"text/template"
1415

@@ -222,7 +223,14 @@ func tag(table *core.Table, col *core.Column) string {
222223
if col.IsUpdated {
223224
res = append(res, "updated")
224225
}
226+
227+
names := make([]string, 0, len(col.Indexes))
225228
for name := range col.Indexes {
229+
names = append(names, name)
230+
}
231+
sort.Strings(names)
232+
233+
for _, name := range names {
226234
index := table.Indexes[name]
227235
var uistr string
228236
if index.Type == core.UniqueType {
@@ -246,15 +254,29 @@ func tag(table *core.Table, col *core.Column) string {
246254
} else if len(col.EnumOptions) > 0 { //enum
247255
nstr += "("
248256
opts := ""
249-
for v, _ := range col.EnumOptions {
257+
258+
enumOptions := make([]string, 0, len(col.EnumOptions))
259+
for enumOption := range col.EnumOptions {
260+
enumOptions = append(enumOptions, enumOption)
261+
}
262+
sort.Strings(enumOptions)
263+
264+
for _, v := range enumOptions {
250265
opts += fmt.Sprintf(",'%v'", v)
251266
}
252267
nstr += strings.TrimLeft(opts, ",")
253268
nstr += ")"
254269
} else if len(col.SetOptions) > 0 { //enum
255270
nstr += "("
256271
opts := ""
257-
for v, _ := range col.SetOptions {
272+
273+
setOptions := make([]string, 0, len(col.SetOptions))
274+
for setOption := range col.SetOptions {
275+
setOptions = append(setOptions, setOption)
276+
}
277+
sort.Strings(setOptions)
278+
279+
for _, v := range setOptions {
258280
opts += fmt.Sprintf(",'%v'", v)
259281
}
260282
nstr += strings.TrimLeft(opts, ",")

0 commit comments

Comments
 (0)