I was watching the following package: https://github.com/olekukonko/tablewriter
And I want to try to print my struct as something like that, but I couldn't covert my array of structs into the array of strings that the package needs.
So I tried something like that:
func print(quakes []Quake) {
var data [][]string
for _, quake := range quakes {
b, err := json.Marshal(quake)
append(data, []string(b))
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Sign", "Rating"})
for _, v := range newData {
table.Append(v)
}
table.Render() // Send output
}
My Quake Struct:
type Quake struct {
Googlemapref string `json:"googlemapref"`
Segree string `json: "degree"`
DataUpdate string `json: "dataUpdate"`
MagType string `json:"magType"`
ObsRegion string `json: "obsRegion"`
Lon string `json:"lon"`
Source string `json: "source"`
Depth int `json:"depth"`
TensorRef string `json:"tensorRef"`
Sensed string `json:"sensed"`
Shakemapid string `json:"shakemapid"`
Time string `json:"time"`
Lat string `json:"lat"`
Shakemapref string `json:"shakemapref"`
Local string `json:"local"`
Magnitud string `json: "magnitud"`
}
Would appreciate some help since I am new in the laguage, thanks a lot