gocarina / gocsv

The GoCSV package aims to provide easy CSV serialization and deserialization to the golang programming language
MIT License
1.95k stars 243 forks source link

Header for nested time.Time field is incorrect #245

Open sgtsquiggs opened 1 year ago

sgtsquiggs commented 1 year ago

See example here: https://go.dev/play/p/LPHV70Rc8KP

package main

import (
    "fmt"
    "time"

    "github.com/gocarina/gocsv"
)

type Nested struct {
    UpdatedAt *time.Time `csv:"updated_at"`
}

type Row struct {
    Name string `csv:"name"`
    Data Nested `csv:"data"`
}

func main() {
    now := time.Now()
    dat := []Row{{Name: "matthew", Data: Nested{UpdatedAt: &now}}}
    csv, err := gocsv.MarshalString(dat)
    if err != nil {
        panic(fmt.Sprintf("marshal failed: %v", err))
    }
    fmt.Println(csv)
}

Expected:

name,data.updated_at
matthew,2009-11-10T23:00:00Z

Got:

name,data.UpdatedAt
matthew,2009-11-10T23:00:00Z
haton14 commented 1 year ago

@sgtsquiggs

I fixed it. Please check it out!