我在Go中有一个 struct ,看起来像这样:
type A struct {
Name string
Type string
Time string
}
我想写一个less
函数来比较两个 struct A,例如
func (s A) less(other A) bool {
if s.Name < other.Name {
return True
}
if other.Name < s.Name {
return False
}
if s.Type < other.Type {
return True
}
if other.Type < s.Type {
return False
}
return s.Time < other.Time
}
我想知道是否有更好的方法/更简单的方法来编写这个逻辑?谢谢!