#Unmarshalling csv to struct not working

5 messages · Page 1 of 1 (latest)

weary nebula
#

So I have a struct

type Row struct {
    module            string            `csv:"Module"`
    side              internal.SwapSide `csv:"Side"`
    fromToken         string            `csv:"From_Token"`
    toToken           string            `csv:"To_Token"`
    amount            float64           `csv:"Amount"`
    pair              string            `csv:"Pair"`
    walletName        string            `csv:"Wallet_Name"`
    monitorDelay      string            `csv:"Monitor_Delay"`
    privateKey        string            `csv:"Private_Key"`
    taskCount         int               `csv:"TaskCount"`
    stopAmount        float64           `csv:"Stop_Amount"`
    transferThreshold float64           `csv:"Transfer_Threshold,omitempty"`
    priceThreshold    float32           `csv:"Price_Threshold,omitempty"`
}```

I have a function to read the file and unmarshall the contents into the struct

```go
func ReadFile(filename string) ([]Row, error) {

    fileContent, err := ioutil.ReadFile(filename)

    if err != nil {
        return nil, err
    }

    var rows []Row

    if err := csvutil.Unmarshal(fileContent, &rows); err != nil {
        return nil, err
    }
    fmt.Println(rows)

    return rows, nil
}```
Here is the setup of my csv, all values are filled but the reason I am posting this is because it spits out this output: ```go
[{    0     0 0 0 0}]```

I will provide a screenshot of my csv file but I have searched everywhere and it was working before but is no longer. Thank you!
tough nebula
#

In type Row. Each member that you want csvutil.Unmarshal to find must have a capitalized name so that it is public not private. Example: Module string, ( not module string).

weary nebula
#

Each field name in the row struct should start with a capital letter

weary nebula