createColumnConfigs returns configuration to hide columns that are not provided in the array. If the array is empty, no filtering will occur!
(header table.Row, columns []string)
| 58 | // that are not provided in the array. If the array is empty, |
| 59 | // no filtering will occur! |
| 60 | func createColumnConfigs(header table.Row, columns []string) []table.ColumnConfig { |
| 61 | if len(columns) == 0 { |
| 62 | return nil |
| 63 | } |
| 64 | columnConfigs := make([]table.ColumnConfig, 0) |
| 65 | for _, headerTextRaw := range header { |
| 66 | headerText, _ := headerTextRaw.(string) |
| 67 | hidden := true |
| 68 | for _, column := range columns { |
| 69 | if strings.EqualFold(strings.ReplaceAll(column, "_", " "), headerText) { |
| 70 | hidden = false |
| 71 | break |
| 72 | } |
| 73 | } |
| 74 | columnConfigs = append(columnConfigs, table.ColumnConfig{ |
| 75 | Name: headerText, |
| 76 | Hidden: hidden, |
| 77 | }) |
| 78 | } |
| 79 | return columnConfigs |
| 80 | } |
| 81 | |
| 82 | // DisplayTable renders a table as a string. The input argument can be: |
| 83 | // - a struct slice. |