1
0
mirror of https://github.com/directorz/mailfull-go.git synced 2025-12-17 17:47:04 +00:00

Implement sort.Interface to required struct slice

This commit is contained in:
teru
2016-07-31 13:41:07 +09:00
parent f3e8f83d5a
commit c9e692a68d
4 changed files with 28 additions and 0 deletions

View File

@@ -13,6 +13,13 @@ type AliasUser struct {
targets []string
}
// AliasUserSlice attaches the methods of sort.Interface to []*AliasUser.
type AliasUserSlice []*AliasUser
func (p AliasUserSlice) Len() int { return len(p) }
func (p AliasUserSlice) Less(i, j int) bool { return p[i].Name() < p[j].Name() }
func (p AliasUserSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// NewAliasUser creates a new AliasUser instance.
func NewAliasUser(name string, targets []string) (*AliasUser, error) {
if !validAliasUserName(name) {