Golang:在编译时间验证标签
我已经使用
type customType struct {
Prop1 string
Prop2 []float64
Prop3 map[float64]float64
}
type someStruct struct {
Var1 customType `customTag:"prop1:hello;prop2:0.15,0.1;prop3:0.15=2,3=4.1"`
}
func main() {
input := &someStruct{}
tagReader(input)
fmt.Println(input.Var1.Prop1) //prints hello
fmt.Println(input.Var1.Prop2[0]) //prints 0.15
}
标签是为我的自定义标签读取器以特定格式编写的。我想在编译本身的fustomtag
标签中捕获问题(如果有)。我运行make
来构建整个项目,因此我还可以在make
中添加一些东西。有选择吗?
我假设可以在构建时间检查json
标签,因为它是最受欢迎的标签。那么,有选择吗?
I have written a custom tag reader using reflect package. Example:
type customType struct {
Prop1 string
Prop2 []float64
Prop3 map[float64]float64
}
type someStruct struct {
Var1 customType `customTag:"prop1:hello;prop2:0.15,0.1;prop3:0.15=2,3=4.1"`
}
func main() {
input := &someStruct{}
tagReader(input)
fmt.Println(input.Var1.Prop1) //prints hello
fmt.Println(input.Var1.Prop2[0]) //prints 0.15
}
The tags are written in a specific format for my custom tag reader. I would like to catch problems (if any) in the customTag
tag at the compile itself. I run a make
to build the whole project, so I can also add something in the make
. Is there an option?
I am assuming there can be a way to check json
tags at the build time, since it is the most popular tag. So, is there an option?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论