tagfmt 库,用来对齐 go 语言的 struct tag 字段
資深大佬 : bigpigeon 2
https://github.com/bigpigeon/tagfmt 除了对齐还可以对 tag key 排序和填充 tag value
一个简单例子
// tagfmt . package main type Example struct { Data string `xml:"data" yaml:"data" json:"data"` OtherData string `xml:"other_data" json:"other_data:omitempty" yaml:"other_data"` } // result package main type Example struct { Data string `xml:"data" yaml:"data" json:"data"` OtherData string `xml:"other_data" json:"other_data:omitempty" yaml:"other_data"` }
大佬有話說 (6)