coai/channel/sequence.go
2023-12-03 11:13:58 +08:00

30 lines
468 B
Go

package channel
import "sort"
func (s *Sequence) Len() int {
return len(*s)
}
func (s *Sequence) Less(i, j int) bool {
return (*s)[i].GetPriority() > (*s)[j].GetPriority()
}
func (s *Sequence) Swap(i, j int) {
(*s)[i], (*s)[j] = (*s)[j], (*s)[i]
}
func (s *Sequence) GetChannelById(id int) *Channel {
for _, channel := range *s {
if channel.Id == id {
return channel
}
}
return nil
}
func (s *Sequence) Sort() {
// sort by priority
sort.Sort(s)
}