diff --git a/aliasdomain.go b/aliasdomain.go index 165ebf2..2a59b57 100644 --- a/aliasdomain.go +++ b/aliasdomain.go @@ -6,6 +6,13 @@ type AliasDomain struct { target string } +// AliasDomainSlice attaches the methods of sort.Interface to []*AliasDomain. +type AliasDomainSlice []*AliasDomain + +func (p AliasDomainSlice) Len() int { return len(p) } +func (p AliasDomainSlice) Less(i, j int) bool { return p[i].Name() < p[j].Name() } +func (p AliasDomainSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } + // NewAliasDomain creates a new AliasDomain instance. func NewAliasDomain(name, target string) (*AliasDomain, error) { if !validAliasDomainName(name) { diff --git a/aliasuser.go b/aliasuser.go index 7b04696..c8deea2 100644 --- a/aliasuser.go +++ b/aliasuser.go @@ -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) { diff --git a/domain.go b/domain.go index 1ca5d37..c1b8cf2 100644 --- a/domain.go +++ b/domain.go @@ -8,6 +8,13 @@ type Domain struct { CatchAllUser *CatchAllUser } +// DomainSlice attaches the methods of sort.Interface to []*Domain. +type DomainSlice []*Domain + +func (p DomainSlice) Len() int { return len(p) } +func (p DomainSlice) Less(i, j int) bool { return p[i].Name() < p[j].Name() } +func (p DomainSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } + // NewDomain creates a new Domain instance. func NewDomain(name string) (*Domain, error) { if !validDomainName(name) { diff --git a/user.go b/user.go index 5899cc0..b6e163b 100644 --- a/user.go +++ b/user.go @@ -7,6 +7,13 @@ type User struct { forwards []string } +// UserSlice attaches the methods of sort.Interface to []*User. +type UserSlice []*User + +func (p UserSlice) Len() int { return len(p) } +func (p UserSlice) Less(i, j int) bool { return p[i].Name() < p[j].Name() } +func (p UserSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } + // NewUser creates a new User instance. func NewUser(name, hashedPassword string, forwards []string) (*User, error) { if !validUserName(name) {