Documentation
¶
Overview ¶
Package parser the schema parser
Index ¶
- Constants
- func Register(key string, parser Parser)
- type Context
- func (c *Context) BaseURL() string
- func (c *Context) Cancel()
- func (c *Context) ClearValue()
- func (c *Context) Deadline() (time.Time, bool)
- func (c *Context) Done() <-chan struct{}
- func (c *Context) Err() error
- func (c *Context) GetValue(key any) (any, bool)
- func (c *Context) Logger() *slog.Logger
- func (c *Context) SetValue(key any, value any)
- func (c *Context) URL() string
- func (c *Context) Value(key any) any
- type Options
- type Parser
Constants ¶
const ( // DefaultTimeout The Context default timeout DefaultTimeout = time.Minute )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context The Parser context
func NewContext ¶
NewContext creates a new Context with Options
func (*Context) Cancel ¶
func (c *Context) Cancel()
Cancel this context releases resources associated with it, so code should call cancel as soon as the operations running in this Context complete.
func (*Context) Deadline ¶
Deadline returns the time when work done on behalf of this context should be canceled. Deadline returns ok==false when no deadline is set. Successive calls to Deadline return the same results.
func (*Context) Done ¶
func (c *Context) Done() <-chan struct{}
Done returns a channel that's closed when work done on behalf of this context should be canceled. Done may return nil if this context can never be canceled. Successive calls to Done return the same value. The close of the Done channel may happen asynchronously, after the cancel function returns.
func (*Context) Err ¶
Err If Done is not yet closed, Err returns nil. If Done is closed, Err returns a non-nil error explaining why: Canceled if the context was canceled or DeadlineExceeded if the context's deadline passed. After Err returns a non-nil error, successive calls to Err return the same error.
func (*Context) GetValue ¶
GetValue returns the value associated with this context for key, or nil if no value is associated with key. Successive calls to Value with the same key returns the same result.
type Parser ¶
type Parser interface {
// GetString gets the string of the content with the given arguments.
// e.g.:
//
// content := `<ul><li>1</li><li>2</li></ul>`
// GetString(ctx, content, "ul li") returns "1\n2"
//
GetString(*Context, any, string) (string, error)
// GetStrings gets the strings of the content with the given arguments.
// e.g.:
//
// content := `<ul><li>1</li><li>2</li></ul>`
// GetStrings(ctx, content, "ul li") returns []string{"1", "2"}
//
GetStrings(*Context, any, string) ([]string, error)
// GetElement gets the element of the content with the given arguments.
// e.g.:
//
// content := `<ul><li>1</li><li>2</li></ul>`
// GetElement(ctx, content, "ul li") returns "<li>1</li>\n<li>2</li>"
//
GetElement(*Context, any, string) (string, error)
// GetElements gets the elements of the content with the given arguments.
// e.g.:
//
// content := `<ul><li>1</li><li>2</li></ul>`
// GetElements(ctx, content, "ul li") returns []string{"<li>1</li>", "<li>2</li>"}
//
GetElements(*Context, any, string) ([]string, error)
}
Parser the content schema
Directories
¶
| Path | Synopsis |
|---|---|
|
parsers
|
|
|
gq
Package gq the goquery parser
|
Package gq the goquery parser |
|
js
Package js the js parser
|
Package js the js parser |
|
json
Package json the json parser
|
Package json the json parser |
|
regex
Package regex the regexp parser
|
Package regex the regexp parser |
|
xpath
Package xpath the xpath parser
|
Package xpath the xpath parser |