Created
October 12, 2019 10:15
-
-
Save guerbai/f149fd85838bac9e8f12babebdff4940 to your computer and use it in GitHub Desktop.
[slice常用方法] #go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/bradfitz/slice" | |
) | |
type ArtistUidInfo struct { | |
ArtistId int64 | |
ArtistOrder int8 | |
InternalID string | |
} | |
func main() { | |
a := &ArtistUidInfo{ | |
ArtistId: 1, | |
ArtistOrder: 1, | |
} | |
b := &ArtistUidInfo{ | |
ArtistId: 2, | |
ArtistOrder: 2, | |
} | |
c := &ArtistUidInfo{ | |
ArtistId: 3, | |
ArtistOrder: 3, | |
} | |
d := []*ArtistUidInfo{b, c, a} | |
for _, e := range d { | |
fmt.Printf("%v", e) | |
} | |
fmt.Printf("%v", d) | |
slice.Sort(d[:], func(i, j int) bool { | |
return d[i].ArtistOrder < d[j].ArtistOrder | |
}) | |
for _, e := range d { | |
fmt.Printf("%v", e) | |
} | |
fmt.Printf("%v", d) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment