Golang:在编译时间验证标签

发布于 2025-02-13 08:22:17 字数 620 浏览 0 评论 0原文

我已经使用

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文