0

I want something like this in go

  1. table

  2. map[string]table

what I have tired for map[string]table is mentioned below but not sure if its the right approach:

package main

import (
    "fmt"
)

type table struct{
    a,b []int
    c []string
}

func main() {
    mytable := make(map[string]table)
    var a1 []int
    var b1 []int
    var c1 []int

    a1=append(a1,1)
    a1=append(a1,1)
    b1=append(b1,2)
    c1=append(c1,"Golang")  

    t1 := table{a1,b1,c1}

    mytable["abc"]=t1
}

I need the table since I will be using the data for the CSV file. Let me know the best approach for doing this.

Adrian
  • 42,911
  • 6
  • 107
  • 99
Junaid s
  • 89
  • 6

1 Answers1

1

You can create a list of "rows", each "row" containing one line of your table:

type Data struct {
  A int
  B int
  C string
}

func main() {
  var table []Data

  table = append(table, Data{A: 1, B: 2, C: "foo"})
  ...
}
cd1
  • 15,908
  • 12
  • 46
  • 47