droyo / go-xml

utility and code-generation libraries for XML
MIT License
304 stars 115 forks source link

generate const values for enumerations #136

Closed SoMuchForSubtlety closed 3 years ago

SoMuchForSubtlety commented 3 years ago

This partly addresses #17 by generating const declarations for enums. I also fixed some linter errors.

Maybe we should omit numerical enums since they don't have useful names?

// May be one of 0.9, 0.333333333, 0.0
type FloatType float64

const (
    FloatType_0_9         FloatType = 0.9
    FloatType_0_333333333 FloatType = 0.333333333
    FloatType_0_0         FloatType = 0.0
)

// May be one of 1, 2, 3
type IntType int

const (
    IntType_1 IntType = 1
    IntType_2 IntType = 2
    IntType_3 IntType = 3
)

It would probably also make sense to gate this behind a config flag, what do you think?