Skip to content

Allow default formatting to be configured at the struct level #38

@ianlopshire

Description

@ianlopshire

As of v0.7.0 formatting is configurable at the struct field level.

type Record struct {
	Field1 string `fixed:"1,5,left,#"`
	Field2 string `fixed:"6,10,left,#"`
	Field3 string `fixed:"11,15,left,#"`
	Field4 string `fixed:"16,20,left,#"`
	...
}

Adding all of the required tags can be tedious when all of the fields require a specific format. To alleviate this, there should be a mechanism to set the default format for all the fields in a struct.

My current thought is to implement something similar to xml.Name.

type Record struct {
	// Format is a special struct that can be embedded into a struct to control
	// the default formatting of its fields.
  	fixedwidth.Format `fixed:"left,#"`

	Field1 string `fixed:"1,5"`
	Field2 string `fixed:"6,10"`
	Field3 string `fixed:"11,15"`
	Field4 string `fixed:"16,20,right,0"` // Override the default formatting.
	...
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions