1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-04-27 12:32:45 +02:00
Tim Voronov e64ad4ec0e
Feature/#33 wait class function ()
*  Lib cleanup. Added WAIT_CLASS and WAIT_CLASS_ALL functions

*  Fixed attr update

*  HTMLElement.WaitForClass

*  Updated HTMLDocument.WaitForClass
2018-10-06 22:33:39 -04:00

47 lines
1.1 KiB
Go

package driver
import (
"context"
"fmt"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/stdlib/html/driver/dynamic"
"github.com/MontFerret/ferret/pkg/stdlib/html/driver/static"
)
type Name string
const (
Dynamic Name = "dynamic"
Static Name = "static"
)
type Driver interface {
GetDocument(ctx context.Context, url values.String) (values.HTMLNode, error)
Close() error
}
func ToContext(ctx context.Context, name Name, drv Driver) context.Context {
return context.WithValue(ctx, name, drv)
}
func FromContext(ctx context.Context, name Name) (Driver, error) {
val := ctx.Value(name)
drv, ok := val.(Driver)
if ok {
return drv, nil
}
return nil, core.Error(core.ErrNotFound, fmt.Sprintf("%s driver", name))
}
func WithDynamicDriver(ctx context.Context, addr string) context.Context {
return context.WithValue(ctx, Dynamic, dynamic.NewDriver(addr))
}
func WithStaticDriver(ctx context.Context, opts ...static.Option) context.Context {
return context.WithValue(ctx, Static, static.NewDriver(opts...))
}