github.com/inspektor-gadget/inspektor-gadget@v0.28.1/pkg/columns/sort/doc.go (about)

     1  // Copyright 2022 The Inspektor Gadget authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  /*
    16  Package sort can be used to sort an array by their columns in either ascending or descending order.
    17  
    18  Calling
    19  
    20  	sort.SortEntries(columnMap, entries, []string{"node", "-time"})
    21  
    22  for example sorts the array by the time column in descending order and afterwards by the node column.
    23  
    24  The "-" prefix means the sorter should use descending order. Sorting by multiple fields will be done from the last field
    25  to the first in a stable way - so the first column always gets the highest priority.
    26  
    27  Three special cases exist:
    28   1. Non-existent columns will be silently ignored.
    29   2. When a virtual column is selected as a column to sort by, that column will be silently ignored.
    30   3. A column with a custom extractor is allowed to sort by.
    31      But the sorting function uses the underlying value instead of the result of the extractor function
    32  
    33  One can use sort.CanSortBy(columnMap, []string{"node", "-time"}) to check if any column will be silently ignored. For more
    34  information the function sort.FilterSortableColumns(columnMap, []string{"node", "-time"}) can be used, which returns two lists.
    35  One with all valid filterable columns and another one with the invalid columns
    36  */
    37  package sort