node

package
v7.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package node 处理 ast 中各个节点的结构信息

struct tag

标签属性分为 4 个字段,其中前三个是必填的:

apidoc:"name,node-type,usage-key,omitempty"

name 表示当前标签的名称,或是节点表示的类型; node-type 表示当前节点的类型,可以是以下值:

  • elem 表示这是一个子元素;
  • attr 表示为一个 XML 属性;
  • cdata 表示为 CDATA 数据;
  • content 表示为普通的字符串值;
  • meta 表示这个字段仅用于描述当前元素的元数据,比如元素的名称等;

usage-key 指定了当前元素的翻译项; omitempty 表示当前值为空时,是否可以忽略。

Index

Constants

View Source
const TagName = "apidoc"

TagName 结构体标签的名称

Variables

This section is empty.

Functions

func IsPrimitive

func IsPrimitive(v reflect.Value) bool

IsPrimitive 是否为有效的 Go 原始类型

func RealType added in v7.1.0

func RealType(t reflect.Type) reflect.Type

RealType 获取指针指向的类型

func RealValue added in v7.1.0

func RealValue(v reflect.Value) reflect.Value

RealValue 获取指针指向的值

如果未初始化,则会对其进行初始化。

Types

type Node

type Node struct {
	Attributes     []*Value // 当前标签的属性值列表
	Elements       []*Value // 当前标签的元素列表
	CData, Content *Value   // 当前标签如果没有子元素,则可能有普通的内容或是 CDATA 内容
	Value          Value    // 当前节点本身代表的值
	TypeName       string   // 当前节点的类型名称
}

Node 表示一个 XML 标签节点

func New

func New(name string, rv reflect.Value) *Node

New 声明 Node 实例

func (*Node) Attribute

func (n *Node) Attribute(name string) (*Value, bool)

Attribute 查找名称为 name 的节点属性

func (*Node) Element

func (n *Node) Element(name string) (*Value, bool)

Element 查找名称为 name 的节点元素

type Type

type Type int8

Type 节点类型

type Value

type Value struct {
	reflect.Value
	Omitempty bool
	Name      string // 节点的名称

	// 当前值可能未初始化,所以保存 usage 的值,
	// 等 Value 初始化之后再赋值给 Base.UsageKey
	Usage string
}

Value 表示 XML 节点的值的反射表示方式

func NewValue

func NewValue(name string, v reflect.Value, omitempty bool, usage string) *Value

NewValue 声明 *Value 实例

func ParseValue

func ParseValue(v reflect.Value) *Value

ParseValue 分析 v 并返回 *Value 实例

与 NewValue 的不同在于,ParseValue 会分析对象字段中是否带有 meta 的结构体标签, 如果有才初始化 *Value 对象,否则返回 nil。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL