How to sort struct with multiple sort parameters?

前端 未结 8 591
囚心锁ツ
囚心锁ツ 2020-12-24 11:24

I have an array/slice of members:

type Member struct {
    Id int
    LastName string
    FirstName string
}

var members []Member

My quest

8条回答
  •  不知归路
    2020-12-24 12:00

    All good answers, If you don't want to write any configuration. You can use the external package to perform sorting.

    go get -d github.com/raunakjodhawat/multisort

    And call the function like so:

    sortedSlice, err := multisort.MultiSorted(inputSlice, inputKeys, SortOrders)

    To look at a concrete example, go to: https://github.com/raunakjodhawat/multisort

提交回复
热议问题