I’m trying to get help on what’s the recommended way of doing the following.
I want to print out selective fields in a struct slice as nice tabular interface. The data I get from HTTP call is in struct slice type and the response may have 10 fields for the struct but I only need to print out several related fields as tabular ascii format for users to see.
For example, the data may contain 100 networks, each network has 10 fields like network name, field, vlan… but I only want to use 3 fields and print out a nice tabular output so users can see name, vlan number for all 100 networks.
I’m looking at tablewriter library but it looks like it wants a two dimensional string slice as input.
If tablewriter is a good way going forward, what’s the recommended way to append selected struct fields to a two-dimensional string slice.
Regular printf with fixed field widths can also work nicely. At least things like IP prefixes and VLAN numbers have known max lengths.
Don’t look for a functional-like operation to map, extract and zip your slice into some other two dimensional slice without looping. It’s not how go does it.