gocarina / gocsv

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

Custom bool marshall #254

Open JakobDev opened 1 year ago

JakobDev commented 1 year ago

I need to output a CSV which has localized bool values. I tried this code according to the Readme:

func (value bool) MarshalCSV() (string, error) {
    if value {
        return "Ja", nil
    } else {
        return "Nein", nil
    }
}

but it fails, because bool is a built-in type.

shigetaichi commented 1 year ago

@JakobDev How about trying this?

type CustomBool struct {
    bool
}

func (b *CustomBool) MarshalCSV() (string, error) {
    if b.bool {
        return "Ja", nil
    } else {
        return "Nein", nil
    }
}