Documentation
¶
Overview ¶
Package syntaxgo_tag provides struct tag parsing and manipulation utilities Parse GORM, JSON, and other tags from struct field tag strings Extract specific fields and values, update tag contents programmatically
syntaxgo_tag 包提供结构体标签解析和操作工具 从结构体字段标签字符串解析 GORM、JSON 和其他标签 提取特定字段和值,以编程方式更新标签内容
Index ¶
- func ExtractFieldEqualsValueIndex(part, fieldName, fieldValue string) (sdx, edx int)
- func ExtractFieldEqualsValueIndexV2(part string, fieldName string, fieldValue string, terminators []string) (int, int)
- func ExtractNoValueFieldNameIndex(part, fieldName string) (sdx, edx int)
- func ExtractTagField(part, fieldName string, action ExtractTagFieldAction) string
- func ExtractTagFieldIndex(part, fieldName string, action ExtractTagFieldAction) (string, int, int)
- func ExtractTagValue(tag, key string) string
- func ExtractTagValueIndex(tag, key string) (string, int, int)
- func SetTagFieldValue(tag, key, field, value string, insertLocation InsertLocation) string
- type ExtractTagFieldAction
- type InsertLocation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractFieldEqualsValueIndex ¶
ExtractFieldEqualsValueIndex returns the start and end positions of the value in a key-value pair, such as `index:idx_abc` or `uniqueIndex:udx_xyz`. The returned coordinates include any surrounding whitespace, which is useful when replacing or modifying the value. ExtractFieldEqualsValueIndex 返回的是键值对中值的坐标 比如匹配的是 index:idx_abc 或者 uniqueIndex:udx_xyz 这种键值对 返回的是值的起止坐标,同时,区间内包含前后的空格
func ExtractFieldEqualsValueIndexV2 ¶
func ExtractFieldEqualsValueIndexV2(part string, fieldName string, fieldValue string, terminators []string) (int, int)
ExtractFieldEqualsValueIndexV2 is similar to the previous function but allows custom terminators to be passed, ExtractFieldEqualsValueIndexV2 和前面的功能相同,但提供自定义分隔符的功能
func ExtractNoValueFieldNameIndex ¶
ExtractNoValueFieldNameIndex is used to extract key names for single-key tags, such as `index` or `uniqueIndex`, where no value is provided. It returns the start and end positions of the key name, including any surrounding spaces. ExtractNoValueFieldNameIndex 匹配单键标签,比如 index 或者 uniqueIndex 这类标签,在简化情况下可以是没有值的 返回的是键名的起止坐标,区间包含键名左右的空格部分
func ExtractTagField ¶
func ExtractTagField(part, fieldName string, action ExtractTagFieldAction) string
ExtractTagField extracts a specific part of a tag, such as `gorm:"column:name"`, considering both scenarios ExtractTagField 提取标签中的特定部分,比如 gorm 里面的 column:name 这部分,Fields Tags
func ExtractTagFieldIndex ¶
func ExtractTagFieldIndex(part, fieldName string, action ExtractTagFieldAction) (string, int, int)
ExtractTagFieldIndex extracts a specific part of the tag field and returns the start and end index of that part in the string. ExtractTagFieldIndex 提取标签字段的特定部分并返回其在字符串中的位置
func ExtractTagValue ¶
ExtractTagValue extracts a specific part of a tag, such as the value of the "gorm" or "json" key in a tag like `gorm:"" json:""`. ExtractTagValue 提取标签中的特定部分,比如 `gorm:"" json:""` 的 gorm 整体 或者 json 整体
func ExtractTagValueIndex ¶
ExtractTagValueIndex extracts the value of a specific key from the tag and returns the value's start and end indexes. ExtractTagValueIndex 提取标签中指定键值对的值并返回该值的位置
func SetTagFieldValue ¶ added in v0.0.40
func SetTagFieldValue(tag, key, field, value string, insertLocation InsertLocation) string
SetTagFieldValue updates the value of an existing field in a struct tag, identified by its key and field name. If the field doesn't exist, it inserts the field at the top or end of the tag. SetTagFieldValue 根据给定的 key 和 field name 更新结构体标签中指定字段的值。 假如字段不存在,它会将新的字段插入到标签的顶部或末尾。
Types ¶
type ExtractTagFieldAction ¶
type ExtractTagFieldAction string
const ( EXCLUDE_WHITESPACE_PREFIX ExtractTagFieldAction = "EXCLUDE_WHITESPACE_PREFIX" //以前传 TRUE 的地方 INCLUDE_WHITESPACE_PREFIX ExtractTagFieldAction = "INCLUDE_WHITESPACE_PREFIX" //以前传 FALSE 的地方 )
type InsertLocation ¶ added in v0.0.40
type InsertLocation string
const ( INSERT_LOCATION_TOP InsertLocation = "TOP" INSERT_LOCATION_END InsertLocation = "END" )