为什么要写这个
主要还是为了加深自己的理解。第一次接触代码生成的东西,这玩意原来也可以分为各种流派的。比如,用 template
来生成整个代码文件。比如用 stringer
来生成一些辅助方法啥的。注意这个 stringer
不是 https://pkg.go.dev/fmt#Stringer, 而是 https://pkg.go.dev/golang.org/x/tools/cmd/stringer。不得不说,咱们国内的文章啊,你得弄清楚啊,第一个 stringer
是个接口啊,你让接口来生成代码么。
先说说 stringer
为啥要拿这个举例,因为有很多的文章都是这个,所以我们也用这个来弄。
Stringer is a tool to automate the creation of methods that satisfy the fmt.Stringer interface. Given the name of a (signed or unsigned) integer type T that has constants defined, stringer will create a new self-contained Go source file implementing
这个是