Let's say I have struct SortableStruct
with 3 fields A
B
C
I want to implement function that consumes sl []SortableStruct
and orderFied string
where orderField
is one of struct's field. This function should retrun slice sorted by orderField
. Is there a way of doing this without huge switch case. It's not ovious for me how to implement sort.Interface
when I want compare structs by different fields.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…