教程集 www.jiaochengji.com
教程集 >  Golang编程  >  golang教程  >  正文 Go结构体struct中的tag标签有什么用?

Go结构体struct中的tag标签有什么用?

发布时间:2023-03-03   编辑:jiaochengji.com
教程集为您提供Go结构体struct中的tag标签有什么用?等资源,欢迎您收藏本站,我们将为您提供最新的Go结构体struct中的tag标签有什么用?资源

本文翻译自:What are the use(s) for tags in Go?

In the Go Language Specification , it mentions a brief overview of tags: 在Go语言规范中 ,它提到了标签的简要概述:

A field declaration may be followed by an optional string literal tag, which becomes an attribute for all the fields in the corresponding field declaration. 字段声明后面可以跟一个可选的字符串文字标记,该标记成为相应字段声明中所有字段的属性。 The tags are made visible through a reflection interface but are otherwise ignored. 标签通过反射界面可见,但否则将被忽略。

 // A struct corresponding to the TimeStamp protocol buffer. // The tag strings define the protocol buffer field numbers. struct { microsec uint64 "field 1" serverIP6 uint64 "field 2" process string "field 3" } 


This is a very short explanation IMO, and I was wondering if anyone could provide me with what use these tags would be? 这是一个非常简短的解释IMO,我想知道是否有人可以提供我这些标签的用途?

您可能感兴趣的文章:
Golang结构体中Tag的使用
golang 结构体struct 标签tag 简介
golang 结构体标签_如何在Go中使用结构标签
Golang适用的DTO工具
Golang 中的 Tags
活学活用golang的反射机制
Go语言--反射(reflect)
Go 反射机制介绍
Go语言学习-结构体与json
Go 学习笔记 09 | Golang 结构体与 JSON 互相转换

[关闭]
~ ~