Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
func Parse(reader io.Reader, options ...ParseOption) error
Parse parses the input stream and triggers callbacks when matching tags are found
Example ¶
ExampleParse demonstrates how to use the aitag parser
input := `这是一些普通文本
<|CODE_abc123|>
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
<|CODE_END_abc123|>
还有更多文本
<|DATA_xyz789|>
{
"name": "example",
"version": "1.0"
}
<|DATA_END_xyz789|>
结束文本`
err := Parse(strings.NewReader(input),
WithCallback("CODE", "abc123", func(reader io.Reader) {
content, _ := io.ReadAll(reader)
fmt.Printf("代码内容:\n%s\n", string(content))
}),
WithCallback("DATA", "xyz789", func(reader io.Reader) {
content, _ := io.ReadAll(reader)
fmt.Printf("数据内容:\n%s\n", string(content))
}),
)
if err != nil {
log.Errorf("解析失败: %v", err)
}
func ParseWithCallbacks ¶
ParseWithCallbacks is a convenience function that allows passing multiple callbacks
Types ¶
type CallbackFunc ¶
CallbackFunc defines the function signature for tag content handlers
type ParseOption ¶
type ParseOption func(*Parser)
ParseOption defines configuration options for the parser
func WithCallback ¶
func WithCallback(tagName, nonce string, callback CallbackFunc) ParseOption
WithCallback registers a callback for a specific tag name and nonce
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser holds the configuration for parsing tagged content
func NewParser ¶
func NewParser(options ...ParseOption) *Parser
NewParser creates a new parser instance
type TagCallback ¶
type TagCallback struct {
TagName string
Nonce string
Callback CallbackFunc
}
TagCallback represents a registered callback for a specific tag and nonce
Click to show internal directories.
Click to hide internal directories.