forked from csweichel/bel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsort-alphabetically.go
42 lines (35 loc) · 897 Bytes
/
sort-alphabetically.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"github.com/laknoll/bel"
)
// StructB is a structure with non-alphabetically sorted fields
type StructB struct {
FieldC string
FieldA string
FieldB string
}
// StructA is a structure with non-alphabetically sorted fields
type StructA struct {
FieldB string
FieldC int
FieldA string
}
// StructC uses StructA and StructB
type StructC struct {
BMember StructB
AMember StructA
}
// SortAlphabetically demonstrates the use of the bel.SortAlphabetically config option
func SortAlphabetically() {
ts, err := bel.Extract(StructC{}, bel.SortAlphabetically, bel.FollowStructs)
if err != nil {
panic(err)
}
err = bel.Render(ts, bel.GenerateAdditionalPreamble("// Note the alphabetical order which is unlike the \"natural\" order of the types and fields\n"))
if err != nil {
panic(err)
}
}
func init() {
examples["sort-alphabetically"] = SortAlphabetically
}