ianlopshire/go-fixedwidth

Simplify the design of go-fixedwidth

Closed this issue · 1 comments

Hi @ianlopshire,

When I have a struct with about 80 fields, I have to spend time to calculate the start and end position for each field, it's really hard to use.
So why don't we just use the fixed length (bytes or codepoints)? I think it is easier for implementing and better user experience also.

My suggestion:

type Nested struct {
	F1 string `fixed:"10"`
	F2 struct {
		E1 string `fixed:"10"`
		E2 string `fixed:"10"`
	}
}

@huydang284,

I can empathize with the tedium involved with dealing with files with so many fields. That being said, I don't support this change to the package. The proposed change couples the struct field order to encoding/decoding in a way that would remove a lot of the flexibility the package currently has.

Perhaps a utility can be added that makes it easier to generate structs when a file spec is given in fixed lengths.