# README
annotation
注释解析器
格式
// {$MagicPrefix}{$Name}({$Key0}={$Value0}, {$Key1}={$Value1}, {$Key2}="{$Value2}" ...)
注意 :
- 字符串类型值需要使用
""
$MagicPrefix
默认为annotation@
例子
// annotation@A( AK=127, AV="AAAAA" )
解析 :
line := `// annotation@A( AK=127, AV="AAAAA" )`
ann, err0 := Default.Resolve(line)
xpanic.WhenError(err0)
fmt.Println("Name:", ann.Name())
fmt.Println("Line:", ann.Line())
akVal, err1 := ann.Int("AK")
xpanic.WhenError(err1)
fmt.Println("AK:", akVal)
fmt.Println("AV:", ann.String("AV"))
Output:
Name: a
Line: // annotation@A( AK=127, AV="AAAAA" )
AK: 127
AV: AAAAA
# Functions
AtomicOptions return atomic *OptionsVisitor.
AtomicOptionsSet atomic setter for *Options.
InstallCallbackOnAtomicOptionsSet install callback.
InstallOptionsWatchDog the installed func will called when NewOptions called.
New 创建一个解析器,默认使用 annotation@ 作为 MagicPrefix,只有包含 MagicPrefix 的行,才能萃取到注释 descriptors 可以指定萃取的注释名,以及是否为合法的注释 若不指定 descriptors,则任意名的注释,均为合法的注释.
No description provided by the author
NewOptions new Options.
go:generate optiongen --option_with_struct_name=false --new_func=NewOptions --xconf=true --empty_composite_nil=true --usage_tag_name=usage.
Resolve 使用默认的解析器 Default 解析一行注释 若未解析成功,则返回 ErrNoAnnotation 错误.
ResolveMany 使用默认的解析器 Default 解析多行注释 该接口会忽略 ErrNoAnnotation 错误.
ResolveNoDuplicate 使用默认的解析器 Default 解析多行注释,但不允许有重复的 Annotation.Name 否则返回错误 该接口会忽略 ErrNoAnnotation 错误.
ResolveWithName 使用默认的解析器 Default 解析多行注释,但要求 Annotation.Name 是指定的 name 参数 否则返回 ErrNoAnnotation 错误.
WithDescriptors 描述数组.
WithLowerKey key是否为转化为小写.
WithMagicPrefix 只有包含 MagicPrefix 的行,才能萃取到注释.
# Variables
Default 默认的解析器,只有包含 'annotation@' 的行,才能萃取到注释.
No description provided by the author
No description provided by the author
# Structs
Descriptor 描述,可以规定萃取的注释名,以及判断萃取的注释是否合法.
Options should use NewOptions to initialize it.
# Interfaces
Annotation 注释.
OptionsInterface visitor + ApplyOption interface for Options.
OptionsVisitor visitor interface for Options.
Resolver 解析器.
# Type aliases
Option option func.